eXist-db / exist-markdown

Markdown Parser in XQuery
Other
13 stars 9 forks source link

[BUG] Curly braces in fenced code blocks are mangled #18

Open joewiz opened 2 years ago

joewiz commented 2 years ago

Expected behavior

Curly braces inside fenced code blocks should be left as literal curly braces.

Actual behavior

Curly braces are replaced with a <span itemprop=""> element.

Reproduction steps

See the pending test at https://github.com/eXist-db/exist-markdown/blob/master/test/xqs/test-suite.xqm#L223-L244.

This test takes this markdown:

```xquery
for $i in 1 to 10
return
    <li>{$i * 2}</li>
```

With this input, the markdown:parse() function should return:

<body>
    <pre data-language="xquery">for $i in 1 to 10
return
    &lt;li&gt;{$i * 2}&lt;/li&gt;
</pre>
</body>

The Commonmark dingus at https://spec.commonmark.org/dingus/ returns something quite similar, so our expectations are inline with Commonmark:

<pre>
    <code class="language-xquery">for $i in 1 to 10
return
    &lt;li&gt;{$i * 2}&lt;/li&gt;
</code>
</pre>

But it actually returns:

<body>
    <pre data-language="xquery">for $i in 1 to 10
return
    &lt;li&gt;<span itemprop="$i * 2">$i * 2</span>&lt;/li&gt;
</pre>
</body>

Note that the curly braces are transformed into a <span itemprop=""> structure - which is associated with the library's handling of "label" at https://github.com/eXist-db/exist-markdown/blob/master/content/markdown.xqm#L119-L128.

Since the parsed markdown doesn't equal the expected output, the test fails (and is marked as pending in the source until a fix is in place):

<testcase name="Code Blocks" class="tests:code-blocks">
    <failure message="assertTrue failed." type="failure-error-code-1"/>
    <output>false</output>
</testcase>

Please provide the following