Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Rendering #629

Merged
merged 1 commit into from
Jun 12, 2021
Merged

XML Rendering #629

merged 1 commit into from
Jun 12, 2021

Conversation

colinodell
Copy link
Member

@colinodell colinodell commented Jun 6, 2021

This PR adds the ability to render an AST to XML. The output closely mirrors the DTD defined alongside the CommonMark spec; as a result, the output provided by this library will almost perfectly match other parsers using the same format. (We deviate from this by allowing non-standard nodes, like those found in extensions, to be included with their own attributes.)

This feature will be particularly useful in developing and debugging custom extensions.

Given Markdown input like this:

# XML Test

**[_CommonMark_](https://spec.commonmark.org) is **awesome**!**

I use the `CommonMarkConverter` everywhere I can!

---

1. item one
2. item two
    - sublist
    - sublist

The new XML renderer will produce output like this:

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://commonmark.org/xml/1.0">
    <heading level="1">
        <text>XML Test</text>
    </heading>
    <paragraph>
        <strong>
            <link destination="https://spec.commonmark.org" title="">
                <emph>
                    <text>CommonMark</text>
                </emph>
            </link>
            <text> is </text>
            <strong>
                <text>awesome</text>
            </strong>
            <text>!</text>
        </strong>
    </paragraph>
    <paragraph>
        <text>I use the </text>
        <code>CommonMarkConverter</code>
        <text> everywhere I can!</text>
    </paragraph>
    <thematic_break />
    <list type="ordered" start="1" tight="true" delimiter="period">
        <item>
            <paragraph>
                <text>item one</text>
            </paragraph>
        </item>
        <item>
            <paragraph>
                <text>item two</text>
            </paragraph>
            <list type="bullet" tight="true">
                <item>
                    <paragraph>
                        <text>sublist</text>
                    </paragraph>
                </item>
                <item>
                    <paragraph>
                        <text>sublist</text>
                    </paragraph>
                </item>
            </list>
        </item>
    </list>
</document>

Closes #431

@colinodell colinodell added the enhancement New functionality or behavior label Jun 6, 2021
@colinodell colinodell added this to the v2.0 milestone Jun 6, 2021
@colinodell colinodell self-assigned this Jun 6, 2021
@colinodell colinodell changed the base branch from main to 2.0 June 6, 2021 22:27
@colinodell colinodell merged commit 4b9bf21 into 2.0 Jun 12, 2021
@colinodell colinodell deleted the render-xml branch June 12, 2021 14:16
@colinodell colinodell restored the render-xml branch June 12, 2021 14:16
@colinodell colinodell deleted the render-xml branch June 12, 2021 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New functionality or behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[2.0] XML Conversion
1 participant