git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: prefer using raw_attribute when enabled.

The `raw_attribute` will be used to mark raw bits, even HTML and LaTeX, and even when `raw_html` and `raw_tex` are enabled, as they are by default. To get the old behavior, disable `raw_attribute` in the writer. Closes #4311.

commit28cad165179378369fcf4d25656ea28357026baa authorJohn MacFarlane <jgm@berkeley.edu> dateThu 18 Jul 2019, 22:30 (7 years ago) parent5c655e8
6 files changed+58−16
src/Text/Pandoc/Writers/Markdown.hs+2−2 test/Tests/Writers/Markdown.hs+1−1 test/command/4164.md+1−1 test/command/macros.md+5−5 test/command/parse-raw.md+2−2 test/writer.markdown+47−5
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -467,6 +467,7 @@ blockToMarkdown' opts b@(RawBlock f str) = do
467467 let renderEmpty = mempty <$ report (BlockNotRendered b)
468468 case () of
469469 _ | plain -> renderEmpty
470+ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
470471 | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
471472 "markdown_mmd", "markdown_strict"] ->
472473 return $ text str <> text "\n"
@@ -484,7 +485,6 @@ blockToMarkdown' opts b@(RawBlock f str) = do
484485 text str <> text "\n"
485486 | isEnabled Ext_raw_attribute opts -> rawAttribBlock
486487 | otherwise -> renderEmpty
487− | isEnabled Ext_raw_attribute opts -> rawAttribBlock
488488 | otherwise -> renderEmpty
489489blockToMarkdown' opts HorizontalRule = do
490490 return $ blankline <> text (replicate (writerColumns opts) '-') <> blankline
@@ -1152,6 +1152,7 @@ inlineToMarkdown opts il@(RawInline f str) = do
11521152 | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
11531153 "markdown_mmd", "markdown_strict"] ->
11541154 return $ text str
1155+ | isEnabled Ext_raw_attribute opts -> rawAttribInline
11551156 | f `elem` ["html", "html5", "html4"] ->
11561157 case () of
11571158 _ | isEnabled Ext_raw_html opts -> return $ text str
@@ -1162,7 +1163,6 @@ inlineToMarkdown opts il@(RawInline f str) = do
11621163 _ | isEnabled Ext_raw_tex opts -> return $ text str
11631164 | isEnabled Ext_raw_attribute opts -> rawAttribInline
11641165 | otherwise -> renderEmpty
1165− | isEnabled Ext_raw_attribute opts -> rawAttribInline
11661166 | otherwise -> renderEmpty
11671167inlineToMarkdown opts (LineBreak) = do
11681168 plain <- asks envPlain
test/Tests/Writers/Markdown.hs+1−1
@@ -40,7 +40,7 @@ infix 4 =:
4040tests :: [TestTree]
4141tests = [ "indented code after list"
4242 =: (orderedList [ para "one" <> para "two" ] <> codeBlock "test")
43− =?> "1. one\n\n two\n\n<!-- -->\n\n test"
43+ =?> "1. one\n\n two\n\n```{=html}\n<!-- -->\n```\n test"
4444 , "list with tight sublist"
4545 =: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
4646 plain "baz" ]
test/command/4164.md+1−1
@@ -12,7 +12,7 @@ Here is inline html:
1212
1313<div>
1414
15−<balise> bla bla
15+`<balise>`{=html} bla bla
1616
1717</div>
1818
test/command/macros.md+5−5
@@ -1,5 +1,5 @@
11```
2−% pandoc -f markdown+latex_macros -t markdown
2+% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
33\newcommand{\my}{\phi}
44$\my+\my$
55^D
@@ -9,7 +9,7 @@ $\phi+\phi$
99```
1010
1111```
12−% pandoc -f markdown-latex_macros -t markdown
12+% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
1313\newcommand{\my}{\phi}
1414$\my+\my$
1515^D
@@ -70,7 +70,7 @@ x &= y\\\end{aligned}\]
7070```
7171
7272```
73−% pandoc -f markdown+latex_macros -t markdown
73+% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
7474\newcommand{\my}{\phi}
7575\begin{equation}
7676\my+\my
@@ -84,7 +84,7 @@ x &= y\\\end{aligned}\]
8484```
8585
8686```
87−% pandoc -f markdown-latex_macros -t markdown
87+% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
8888\newcommand{\my}{\phi}
8989\begin{equation}
9090\my+\my
@@ -98,7 +98,7 @@ x &= y\\\end{aligned}\]
9898```
9999
100100```
101−% pandoc -f markdown+latex_macros -t markdown
101+% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
102102\newcommand{\my}{\emph{a}}
103103\my
104104^D
test/command/parse-raw.md+2−2
@@ -2,7 +2,7 @@
22% pandoc -f latex+raw_tex -t markdown
33\emph{Hi \foo{there}}
44^D
5−*Hi \foo{there}*
5+*Hi `\foo{there}`{=latex}*
66```
77
88```
@@ -16,7 +16,7 @@
1616% pandoc -f html+raw_html -t markdown
1717<em>Hi <blink>there</blink></em>
1818^D
19−*Hi <blink>there</blink>*
19+*Hi `<blink>`{=html}there`</blink>`{=html}*
2020```
2121
2222```
test/writer.markdown+47−5
@@ -399,18 +399,35 @@ bar
399399
400400Interpreted markdown in a table:
401401
402+```{=html}
402403<table>
404+```
405+```{=html}
403406<tr>
407+```
408+```{=html}
404409<td>
410+```
405411This is *emphasized*
412+```{=html}
406413</td>
414+```
415+```{=html}
407416<td>
417+```
408418And this is **strong**
419+```{=html}
409420</td>
421+```
422+```{=html}
410423</tr>
424+```
425+```{=html}
411426</table>
427+```
428+```{=html}
412429<script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
413−
430+```
414431Here's a simple block:
415432
416433<div>
@@ -447,41 +464,64 @@ foo
447464
448465This should just be an HTML comment:
449466
467+```{=html}
450468<!-- Comment -->
451−
469+```
452470Multiline:
453471
472+```{=html}
454473<!--
455474Blah
456475Blah
457476-->
477+```
478+```{=html}
458479<!--
459480 This is another comment.
460481-->
461−
482+```
462483Code block:
463484
464485 <!-- Comment -->
465486
466487Just plain comment, with trailing spaces on the line:
467488
489+```{=html}
468490<!-- foo -->
469−
491+```
470492Code:
471493
472494 <hr />
473495
474496Hr's:
475497
498+```{=html}
476499<hr>
500+```
501+```{=html}
477502<hr />
503+```
504+```{=html}
478505<hr />
506+```
507+```{=html}
479508<hr>
509+```
510+```{=html}
480511<hr />
512+```
513+```{=html}
481514<hr />
515+```
516+```{=html}
482517<hr class="foo" id="bar" />
518+```
519+```{=html}
483520<hr class="foo" id="bar" />
521+```
522+```{=html}
484523<hr class="foo" id="bar">
524+```
485525
486526------------------------------------------------------------------------------
487527
@@ -540,7 +580,7 @@ Ellipses...and...and....
540580LaTeX
541581=====
542582
543−- \cite[22-23]{smith.1899}
583+- `\cite[22-23]{smith.1899}`{=tex}
544584- $2+2=4$
545585- $x \in y$
546586- $\alpha \wedge \omega$
@@ -560,11 +600,13 @@ These shouldn't be math:
560600
561601Here's a LaTeX table:
562602
603+```{=tex}
563604\begin{tabular}{|l|l|}\hline
564605Animal & Number \\ \hline
565606Dog & 2 \\
566607Cat & 1 \\ \hline
567608\end{tabular}
609+```
568610
569611------------------------------------------------------------------------------
570612