Redlines.DOCX (redlines v0.9.2)

View Source

Extract track changes from DOCX files by parsing word/document.xml.

Summary

Functions

Accept tracked changes in a DOCX and return the cleaned DOCX bytes.

Like clean/2, but accepts raw DOCX bytes.

Like clean_binary/2, but also returns informational warnings about revision markup that was present while cleaning.

Like clean/2, but also returns informational warnings about revision markup that was present while cleaning.

Extract raw DOCX track changes.

Convert a raw %{insertions: [...], deletions: [...]} map into normalized changes.

Types

clean_warning()

@type clean_warning() :: %{
  type: :revision_markup,
  part: String.t(),
  element: String.t(),
  count: non_neg_integer()
}

Functions

clean(docx_path, opts \\ [])

@spec clean(
  Path.t(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Accept tracked changes in a DOCX and return the cleaned DOCX bytes.

This rewrites XML parts inside the DOCX zip (by default just word/document.xml) by removing deletions (<w:del>…</w:del>) and unwrapping insertions (<w:ins>…</w:ins>).

Options

  • :parts - Zip entry names to clean (default ["word/document.xml"])

clean_binary(docx_binary, opts \\ [])

@spec clean_binary(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Like clean/2, but accepts raw DOCX bytes.

clean_binary_with_warnings(docx_binary, opts \\ [])

@spec clean_binary_with_warnings(
  binary(),
  keyword()
) :: {:ok, binary(), [clean_warning()]} | {:error, term()}

Like clean_binary/2, but also returns informational warnings about revision markup that was present while cleaning.

See clean_with_warnings/2.

clean_with_warnings(docx_path, opts \\ [])

@spec clean_with_warnings(
  Path.t(),
  keyword()
) :: {:ok, binary(), [clean_warning()]} | {:error, term()}

Like clean/2, but also returns informational warnings about revision markup that was present while cleaning.

Each warning includes the zip :part (e.g. "word/document.xml"), an :element (e.g. "w:rPrChange") and a :count.

Options

  • :parts - Zip entry names to clean (default ["word/document.xml"])

extract_track_changes(docx_path)

@spec extract_track_changes(Path.t()) :: {:ok, map()} | {:error, term()}

Extract raw DOCX track changes.

Returns a map with :insertions and :deletions, each containing a list of maps with keys: :id, :author, :date, and :text.

to_changes(arg1)

@spec to_changes(map()) :: [Redlines.Change.t()]

Convert a raw %{insertions: [...], deletions: [...]} map into normalized changes.