jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.74k stars 3.39k forks source link

reStructuredText metadata is wrapped in <p> #7766

Closed not-my-profile closed 1 month ago

not-my-profile commented 2 years ago

Explain the problem.

$ echo '$foo$' > /tmp/foo.html
$ printf '---\nfoo: bar\n---' | pandoc -f markdown --template=/tmp/foo.html
bar
$ printf '=\nA\n=\n:foo: bar' | pandoc -f rst --template=/tmp/foo.html
<p>bar</p>

With RST the metadata value is wrapped in a <p> tag meaning variables cannot be interpolated into attribute values.

(It's worth noting that docutils also does some paragraph normalization).

On a related note it would be nice if lists were preserved as well:

$ printf '$for(foo)$xx $foo$ xx\n$endfor$' > /tmp/foo.html
$ printf '---\nfoo: [bar, baz]\n---' | pandoc -f markdown --template=/tmp/foo.html
xx bar xx
xx baz xx
$ printf '=\nA\n=\n:foo: - bar\n - buz' | pandoc -f rst --template=/tmp/foo.html
xx <ul>
<li>bar</li>
<li>buz</li>
</ul> xx

Pandoc version? pandoc 2.16.2 on Linux

jgm commented 2 years ago

rst2xml gives:

<docinfo><field classes="foo"><field_name>foo</field_name><field_body><paragraph>bar</paragraph></field_body></field></docinfo>

for your input. Note the <paragraph>. So I think pandoc's behavior is correct here. (Note that pandoc removes the paragraph from title, author, date.)

not-my-profile commented 2 years ago

Interesting. printf '=\nA\n=\n:foo: bar' | rst2html gives

<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr class="foo field"><th class="docinfo-name">foo:</th><td class="field-body">bar</td>
</tr>
</tbody>
</table>

Note that there is no <p>. This issue is specifically about being able to interpolate non-standard metadata without the <p> wrapping.

jgm commented 2 years ago

Interesting. We could easily convert all single Para metadata fields into single Plain ones. But I don't know if that's the right behavior either. Note:


% printf '=\nA\n=\n:abstract: bar' | rst2html
...snip...
<div class="abstract topic">
<p class="topic-title">Abstract</p>
<p>bar</p>
</div>
...