fletcher / MultiMarkdown-6

Lightweight markup processor to produce HTML, LaTeX, and more.
https://fletcher.github.io/MultiMarkdown-6/
Other
623 stars 90 forks source link

ODF Header metadata field escapes XML characters and inserts data into wrong position #225

Open AmberHaelo opened 3 years ago

AmberHaelo commented 3 years ago

Version: MultiMarkdown 6 v6.6.0
Problem Description: In attempting to insert a custom paragraph style into a document's FODT header, I found that the ODF Header metadata field, which is described in the documentation as being useful for such tasks, produces a result that cannot be validly inserted into the file, because all of the XML characters within the metadata value field are escaped, and the string is injected into a place that greatly reduces its utility.

Input

Title: Test ODF Header Insertion
ODF Header:
    <office:styles>
        <style:style style:name="Scene_20_Break" style:display-name="Scene Break" style:family="paragraph" style:parent-style-name="Standard">
            <style:paragraph-properties fo:margin-left="0pt" fo:margin-right="0pt" fo:margin-top="15.59pt" fo:margin-bottom="15.59pt" style:contextual-spacing="false" fo:text-align="center" style:justify-single-word="false" fo:text-indent="0pt" style:auto-text-indent="false"/>
        </style:style>
    </office:styles>

# Sample Document #

Whik gronk; thung epp rintax whik jince...

Output (Excerpt)

<office:meta>
    <dc:title>Test ODF Header Insertion</dc:title>
    <dc:creator>AmberHaelo</dc:creator>
    <meta:user-defined meta:name="customfield">If all we can do is insert XML into the office:meta element, we might as well just use custom metadata fields.</meta:user-defined>
&lt;office:styles&gt; &lt;style:style style:name=&quot;Scene_20_Break&quot; style:display-name=&quot;Scene Break&quot; style:family=&quot;paragraph&quot; style:parent-style-name=&quot;Standard&quot;&gt; &lt;style:paragraph-properties fo:margin-left=&quot;0pt&quot; fo:margin-right=&quot;0pt&quot; fo:margin-top=&quot;15.59pt&quot; fo:margin-bottom=&quot;15.59pt&quot; style:contextual-spacing=&quot;false&quot; fo:text-align=&quot;center&quot; style:justify-single-word=&quot;false&quot; fo:text-indent=&quot;0pt&quot; style:auto-text-indent=&quot;false&quot;/&gt; &lt;/style:style&gt; &lt;/office:styles&gt;</office:meta>

Expected Output (Excerpt)

<office:meta>
    <dc:title>Test ODF Header Insertion</dc:title>
    <dc:creator>AmberHaelo</dc:creator>
    <meta:user-defined meta:name="customfield">If all we can do is insert XML into the office:meta element, we might as well just use custom metadata fields.</meta:user-defined>
</office:meta>
<office:styles>
    <style:style style:name="Scene_20_Break" style:display-name="Scene Break" style:family="paragraph" style:parent-style-name="Standard">
        <style:paragraph-properties fo:margin-left="0pt" fo:margin-right="0pt" fo:margin-top="15.59pt" fo:margin-bottom="15.59pt" style:contextual-spacing="false" fo:text-align="center" style:justify-single-word="false" fo:text-indent="0pt" style:auto-text-indent="false"/>
    </style:style>
</office:styles>

As noted in the sample text itself, the other problem with the output is that the field string is inserted directly into the office:meta element. This limits the usefulness of the ODF Header metadata field to inserting metadata, as I understand it, which we might as well do using the native support for adding custom fields.

I thus suggest that to resolve the current lack of utility with this field, the following two changes be made: