Pandoc: Header attributes are ignored when header contains an inline code block

Created on 20 Dec 2016  Â·  2Comments  Â·  Source: jgm/pandoc

I'm in version 1.19.1 and have the following output when converting from Markdown to LaTeX:

➜  ~ echo '# foo {#bar}' | pandoc -t latex 
\section{foo}\label{bar}
➜  ~ echo '# `foo` {#bar}' | pandoc -t latex
\section{\texorpdfstring{\texttt{foo}}{foo}}\label{foo}

In the second example, I expected the section label to be {#bar}, as in the first case.

Converting the same Markdown to HTML shows that the attribute is being associated to the code block:

➜  ~ echo '# `foo` {#bar}' | pandoc -t html 
<h1 id="foo"><code id="bar">foo</code></h1>

Is it the expected behavior?

Most helpful comment

Indeed, with bracketed spans, links, and images we require
the attribute specification to come right after, with no
intervening space.

We should do the same with code spans, to be consistent.

Note, however, that such a change has a chance of breaking
some existing documents.

All 2 comments

Its seems that's what's happening. pandoc is processing the attribute string {#bar} as being associated with the code segment, instead of the heading.

You could disable the extension inline_code_attributes, or as a workaround you could add an escaped space in between the code and the attribute string \ like so:

# `foo`\ {#bar}

which results in:

\section{\texorpdfstring{\texttt{foo}~}{foo~}}\label{bar}

I think this is an edge case that might need some looking at, and agree this is unexpected behavior. Adding a heading attribute string after a space or tab is normal usage, so I'm not sure it makes sense to ignore the whitespace between inline code and an attribute string in this context.

Indeed, with bracketed spans, links, and images we require
the attribute specification to come right after, with no
intervening space.

We should do the same with code spans, to be consistent.

Note, however, that such a change has a chance of breaking
some existing documents.

Was this page helpful?
0 / 5 - 0 ratings