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

The self-contained mode can mangle JavaScript in Markdown #1248

Closed
yihui opened this issue Apr 14, 2014 · 4 comments
Closed

The self-contained mode can mangle JavaScript in Markdown #1248

yihui opened this issue Apr 14, 2014 · 4 comments

Comments

@yihui
Copy link
Contributor

yihui commented Apr 14, 2014

Here is a minimal test case test.md:

hello world!

<script type="text/javascript">
var pow = 1.2, value=5;
while (pow<value) {
pow *= 2;
}
</script>

I convert it to HTML using Pandoc 1.12.3:

pandoc test.md -o test.html --self-contained

And I get the HTML output:

....
<p>hello world!</p>
<script type="text/javascript">
var pow = 1.2, value=5;
while (pow<value) { pow *="2;" } < script>
</body>
....

There are two problems in the conversion:

  1. pow *= 2; becomes pow *="2;", which is invalid in JavaScript;
  2. </script> becomes < script> (/ was removed for some reason).
@yihui
Copy link
Contributor Author

yihui commented Apr 14, 2014

Thanks for the hint! Here is a full example: http://stackoverflow.com/q/23021317/559676 I had to turn off the --self-contained option to preserve the JavaScript code.

According to the documentation, the text between <script> and </script> should not be affected by the extension markdown_in_html_blocks:

There is one exception to this rule: text between <script> and <style> tags is not interpreted as markdown.

@Thell
Copy link

Thell commented Apr 14, 2014

Sorry about the @yihui, my bad re: markdown_in_html_blocks, I had removed it after realizing that I couldn't reproduce the problem either from the command line or via RStudio. FWIW, I also can't reproduce a problem with the full example you just posted either via RStudio Version 0.98.760 with supplied pandoc using render(), or knit/pandoc or from the command line with pandoc; the only issue is a font warning from open3d().

[Edit] - I forgot I had linked the RStudio pandoc to ~/.cabal/bin/pandoc which is version 1.12.3.3!! After switching it back, a message that javascript was required was on the page, but only when using render() from rstudio, not with knit/pandoc or pandoc from the commandline.

@jgm
Copy link
Owner

jgm commented Apr 14, 2014

This is a bug in tagsoup 0.13 which has been fixed in tagsoup 0.13.1:
https://hackage.haskell.org/package/tagsoup-0.13.1/changelog

I can confirm that the problem goes away if you compile against tagsoup 0.13.1:

cabal install pandoc --constrain 'tagsoup==0.13.1'

jgm added a commit that referenced this issue Apr 15, 2014
This fixes a bug in parsing of script tags.
See #1248.
@jgm jgm closed this as completed Apr 15, 2014
@yihui
Copy link
Contributor Author

yihui commented Apr 15, 2014

Perfect. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants