lierdakil / pandoc-crossref

Pandoc filter for cross-references
https://lierdakil.github.io/pandoc-crossref/
GNU General Public License v2.0
936 stars 74 forks source link

Unwanted `<br />` are inserted when using `eqnBlockTemplate` with HTML output #415

Open UlyssesZh opened 10 months ago

UlyssesZh commented 10 months ago

test.yml:

tableEqns: true
eqnBlockTemplate: '<table><tr><td>$$t$$</td><td>$$i$$</td></tr></table>'

test.md:

$$x=y$$ {#eq:test}

Command:

pandoc -f markdown -t html5 -M crossrefYaml=test.yml -F pandoc-crossref test.md

Output:

<div id="eq:test">
<table><br />
<tr><br />
<td><br />
<span class="math display"><em>x</em> = <em>y</em></span><br />
</td><br />
<td><br />
<span class="math display">(1)</span><br />
</td><br />
</tr><br />
</table>
</div>
UlyssesZh commented 10 months ago

Seems that it is intended that we should use raw blocks.

tableEqns: true
eqnBlockTemplate: '`<table><tr><td>`{=html}$$t$$`</td><td>`{=html}$$i$$`</td></tr></table>`{=html}'
lierdakil commented 9 months ago

So there's some weirdness in the parser, but the <br/>s go away if you use the multiline yaml syntax:

---
tableEqns: true
eqnBlockTemplate: |
  <table><tr><td>$$t$$</td><td>$$i$$</td></tr></table>
---

$$e^{i\pi} = -1$${#eq:eq}

@eq:eq

nets us

<div id="eq:eq">
<table>
<tr>
<td>
<span
class="math display"><em>e</em><sup><em>i</em><em>π</em></sup> =  − 1</span>
</td>
<td>
<span class="math display">(1)</span>
</td>
</tr>
</table>
</div>
<p>eq. 1</p>
UlyssesZh commented 9 months ago

Is it a problem with the YAML parser?

lierdakil commented 9 months ago

Dunno, but AFAICT it's on the pandoc side. If you feed the following Markdown

---
eqnBlockTemplate: <table><tr><td>$$t$$</td><td>$$i$$</td></tr></table>
---

into pandoc -t native -s, you can see it inserts line breaks after each tag:

Pandoc
  Meta
    { unMeta =
        fromList
          [ ( "eqnBlockTemplate"
            , MetaInlines
                [ RawInline (Format "html") "<table>"
                , LineBreak
                , RawInline (Format "html") "<tr>"
                , LineBreak
                , RawInline (Format "html") "<td>"
                , LineBreak
                , Math DisplayMath "t"
                , LineBreak
                , RawInline (Format "html") "</td>"
                , LineBreak
                , RawInline (Format "html") "<td>"
                , LineBreak
                , Math DisplayMath "i"
                , LineBreak
                , RawInline (Format "html") "</td>"
                , LineBreak
                , RawInline (Format "html") "</tr>"
                , LineBreak
                , RawInline (Format "html") "</table>"
                ]
            )
          ]
    }
  []

You can also notice it's treating tags as inline, which it doesn't if you use multiline syntax. The <br/> seems unintentional, but the inline thing seems not.