Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webtex generated image in Markdown does not convert to HTML due to newline #7892

Closed
cderv opened this issue Feb 3, 2022 · 0 comments
Closed
Labels

Comments

@cderv
Copy link
Contributor

cderv commented Feb 3, 2022

From https://groups.google.com/g/pandoc-discuss/c/rRAh4z3l_BY

Take this md document

$ echo -e '$$\n\\frac{x}{y}\n$$' > test.md
$ cat test.md
$$
\frac{x}{y}
$$

It can be converted using webtex in Markdown to use an image

$ pandoc -t gfm --webtex test.md
![
\\frac{x}{y}
](https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A "
\frac{x}{y}
")

There is some new line inserted inside what should be an image link in markdown. I was expecting this ![\\frac{x}{y}](https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A "\frac{x}{y}")

This creates issues when trying to convert to HTML

$ pandoc -t markdown --webtex -o test-webtex.md test.md

$ ​cat test-webtex.md
![
\\frac{x}{y}
](https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A "
\frac{x}{y}
")

$pandoc -f markdown -t html test-webtex.md
<p>[
\frac{x}{y}](https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A
” “)</p>```


$ pandoc -t native -f markdown test-webtex.md
[ Para
  ​​[ Str "["
  ​​, SoftBreak
  ​​, Str
      ​​"\\frac{x}{y}](https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A"
  ​​, Space
  ​​, Str "\8221"
  ​​, SoftBreak
  ​​, RawInline (Format "tex") "\\frac{x}{y}"
  ​​, SoftBreak
  ​​, Str "\8220)"
  ​​]
]

From @jgm

Looks like the parser expects a non-space character after the
opening " in a link/image title. So we should avoid a break
there.

BAD:

% pandoc
[
a
](url "
title
")
<p>[ a](url ” title “)</p>

OK:

% pandoc
[
a
](url "title
title
")
<p><a href="url" title="title title">a</a></p>


With gfm reader it does not see the same thing

$ pandoc -t native -f gfm test-webtex.md
[ Para
   ​[ Image
       ​( "" , [] , [] )
       ​[ SoftBreak , Str "\\frac{x}{y}" , SoftBreak ]
       ​( "https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bx%7D%7By%7D%0A"
       ​, "\n\\frac{x}{y}\n"
       ​)
   ​]
]

From @jgm
gfm reader is commonmark and uses a different parser, which
doesn't mind the line break there.

So there are two possible solutions:

  1. fix markdown reader so it's okay with the line break after "
    in title.

  2. fix writer so it strips out the leading and trailing space of
    a title.

Probably worth doing both.

@cderv cderv added the bug label Feb 3, 2022
@jgm jgm closed this as completed in b9ac243 Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant