docx4j icon indicating copy to clipboard operation
docx4j copied to clipboard

Word handling of bookmark in bodgy SDT

Open plutext opened this issue 4 years ago • 0 comments

Word complains on opening:

    <w:sdt>
      <w:sdtPr>
        <w:id w:val="1878500809"/>
        <w:text/>
      </w:sdtPr>
      <w:sdtContent>
        <w:p >
          <w:bookmarkStart w:name="_Toc392995191" w:id="191"/>
          <w:r>
            <w:t>foo</w:t>
          </w:r>
          <w:bookmarkEnd w:id="191"/>
        </w:p>
      </w:sdtContent>
    </w:sdt>

Note this is a block level SDT which incorrectly has a w:text tag.

Adding the bookmark causes Word to complain on opening.

Word repairs it, not by removing w:text, but by using w:displacedByCustomXml="next"

    <w:bookmarkStart w:id="0" w:name="_Toc392995191" w:displacedByCustomXml="next"/>
    <w:sdt>
      <w:sdtPr>
        <w:id w:val="1878500809"/>
        <w:text/>
      </w:sdtPr>
      <w:sdtEndPr/>
      <w:sdtContent>
        <w:p>
          <w:r>
            <w:t>foo</w:t>
          </w:r>
        </w:p>
        <w:bookmarkEnd w:id="0" w:displacedByCustomXml="next"/>
      </w:sdtContent>
    </w:sdt>

plutext avatar Nov 09 '20 22:11 plutext