Ootempl.Xml.Normalizer (ootempl v0.4.0)
XML normalization for fragmented placeholders in Word documents.
Microsoft Word often fragments placeholders across multiple XML runs and text
elements due to spell-checking, grammar-checking, formatting changes, or editing
history. This module normalizes the XML so every {{...}} token sits inside a
single <w:t> element, without merging runs.
The whole token is moved into the <w:t> where it starts, and the pieces of it
are removed from the elements that follow. Text outside the token stays in its
original run, so its formatting, attributes and any non-text run content
(tabs, breaks, symbols, fields) are untouched. The token takes the formatting
of the run it starts in, which is how Word itself treats a selection.
Zero-width markers that Word scatters between runs (proofing errors, bookmarks, comment and permission ranges) do not interrupt a token. Runs nested in paragraph-level containers such as hyperlinks, tracked insertions, smart tags and content controls are normalized within their container.
Example
Fragmented placeholder:
<w:r><w:rPr><w:b/></w:rPr><w:t>Hello {{</w:t></w:r>
<w:proofErr w:type="gramStart"/>
<w:r><w:t>person.first</w:t></w:r>
<w:proofErr w:type="gramEnd"/>
<w:r><w:t>_name}}, how are you?</w:t></w:r>After normalization:
<w:r><w:rPr><w:b/></w:rPr><w:t>Hello {{person.first_name}}</w:t></w:r>
<w:proofErr w:type="gramStart"/>
<w:proofErr w:type="gramEnd"/>
<w:r><w:t>, how are you?</w:t></w:r>Usage
{:ok, xml_doc} = Ootempl.Xml.parse(xml_string)
normalized_doc = Ootempl.Xml.Normalizer.normalize(xml_doc)
{:ok, output} = Ootempl.Xml.serialize(normalized_doc)
Summary
Functions
Normalizes an XML document by moving each fragmented {{...}} token into the
<w:t> element where it starts.
Functions
@spec normalize(Ootempl.Xml.xml_node()) :: Ootempl.Xml.xml_node()
Normalizes an XML document by moving each fragmented {{...}} token into the
<w:t> element where it starts.
Recursively traverses the XML tree; any element whose children include runs is normalized.
Parameters
xml_node- An xmerl XML element or text node
Returns
- The normalized XML node