jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.62k stars 3.38k forks source link

Inline code after the line break sometimes produces unexpected results #5789

Closed Kzer-Za closed 5 years ago

Kzer-Za commented 5 years ago

I have the following markdown code:

`$#` --- Stores the number of command-line arguments that were passed to the shell program  
`$?` --- Stores the exit value of the last command that was executed  
`$0` --- Stores the first word of the entered command (the name of the shell program)  
`$*` --- Stores all the arguments that were entered on the command line ($1 $2 ...)  
`"$@"` --- Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...)  
`$-` --- Option flags of the current shell  
`$$` --- Expands to the decimal process ID of the invoked shell

Converting it to html with pandoc tmp.md -o out.html results in this code:

<p><code>$#</code> — Stores the number of command-line arguments that were passed to the shell program<br />
<code>$?</code> — Stores the exit value of the last command that was executed<br />
<code>$0</code> — Stores the first word of the entered command (the name of the shell program)<br />
<code>$*</code> — Stores all the arguments that were entered on the command line ($1 <span class="math inline">$2 ...) `"$</span>@"<code>--- Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...)</code><span class="math inline">$-` --- Option flags of the current shell `$</span>$` — Expands to the decimal process ID of the invoked shell</p>

The expected result was this:

<p><code>$#</code> --- Stores the number of command-line arguments that were passed to the shell program<br />
<code>$?</code> --- Stores the exit value of the last command that was executed<br />
<code>$0</code> --- Stores the first word of the entered command (the name of the shell program)<br />
<code>$*</code> --- Stores all the arguments that were entered on the command line ($1 $2 ...)<br />
<code>&quot;$@&quot;</code> --- Stores all the arguments that were entered on the command line, individually quoted (&quot;$1&quot; &quot;$2&quot; ...)<br />
<code>$-</code> --- Option flags of the current shell<br />
<code>$$</code> --- Expands to the decimal process ID of the invoked shell</p>

Here is the warning and output produced by the command pandoc tmp.md -o out.html:

[WARNING] Could not convert TeX math '2 ...) `"', rendering as TeX:
  2 ...) `"
         ^
  unexpected '`'
  expecting "\\bangle", "\\brace", "\\brack", "\\choose", "\\displaystyle", "{", letter, digit, ".", "\\mbox", "\\text", "\\textbf", "\\textit", "\\textrm", "\\textsf", "\\texttt", "\\bm", "\\boldsymbol", "\\mathbb", "\\mathbf", "\\mathbfcal", "\\mathbffrak", "\\mathbfit", "\\mathbfscr", "\\mathbfsfit", "\\mathbfsfup", "\\mathbfup", "\\mathbold", "\\mathcal", "\\mathds", "\\mathfrak", "\\mathit", "\\mathrm", "\\mathscr", "\\mathsf", "\\mathsfit", "\\mathsfup", "\\mathtt", "\\mathup", "\\pmb", "\\symbf", "\\texttt", "\\sqrt", "\\surd", "\\mspace", "\\hspace", "\\mathop", "\\mathrel", "\\mathbin", "\\mathord", "\\mathopen", "\\mathclose", "\\mathpunct", "\\phantom", "\\boxed", "\\overset", "\\stackrel", "\\underset", "\\frac", "\\tfrac", "\\dfrac", "\\binom", "\\genfrac", "\\substack", "_", "^", "\\begin", "\\ensuremath", "\\bigg", "\\Bigg", "\\big", "\\Big", "\\biggr", "\\Biggr", "\\bigr", "\\Bigr", "\\biggl", "\\Biggl", "\\bigl", "\\", "\\left", "\\not", "!", "'", "''", "'''", "''''", "*", "+", ",", "-", ".", "/", ":", ":=", ";", "<", "=", ">", "?", "@", "~", "\\operatorname" or end of input
[WARNING] Could not convert TeX math '-` --- Option flags of the current shell `', rendering as TeX:
  -` --- Option flags of the current shell
   ^
  unexpected '`'
  expecting "\\bangle", "\\brace", "\\brack", "\\choose", "\\displaystyle", "{", letter, digit, ".", "\\mbox", "\\text", "\\textbf", "\\textit", "\\textrm", "\\textsf", "\\texttt", "\\bm", "\\boldsymbol", "\\mathbb", "\\mathbf", "\\mathbfcal", "\\mathbffrak", "\\mathbfit", "\\mathbfscr", "\\mathbfsfit", "\\mathbfsfup", "\\mathbfup", "\\mathbold", "\\mathcal", "\\mathds", "\\mathfrak", "\\mathit", "\\mathrm", "\\mathscr", "\\mathsf", "\\mathsfit", "\\mathsfup", "\\mathtt", "\\mathup", "\\pmb", "\\symbf", "\\texttt", "\\sqrt", "\\surd", "\\mspace", "\\hspace", "\\mathop", "\\mathrel", "\\mathbin", "\\mathord", "\\mathopen", "\\mathclose", "\\mathpunct", "\\phantom", "\\boxed", "\\overset", "\\stackrel", "\\underset", "\\frac", "\\tfrac", "\\dfrac", "\\binom", "\\genfrac", "\\substack", "_", "^", "\\begin", "\\ensuremath", "\\bigg", "\\Bigg", "\\big", "\\Big", "\\biggr", "\\Biggr", "\\bigr", "\\Bigr", "\\biggl", "\\Biggl", "\\bigl", "\\", "\\left", "\\not", "!", "'", "''", "'''", "''''", "*", "+", ",", "-", ".", "/", ":", ":=", ";", "<", "=", ">", "?", "@", "~", "\\operatorname" or end of input

My OS is Linux, Pandoc version is 2.7.3.

jgm commented 5 years ago

The

$2 ...)  
`"$

is getting parsed as inline math. If you don't need math you can simply disable this extension, using markdown-tex_math_dollars. You can also escape the $ to prevent it.

Kzer-Za commented 5 years ago

Ah, sorry about it then.