Skip to content

Commit

Permalink
Markdown writer: prefer using raw_attribute when enabled.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Jul 19, 2019
1 parent 5c655e8 commit 28cad16
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Text/Pandoc/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ blockToMarkdown' opts b@(RawBlock f str) = do
let renderEmpty = mempty <$ report (BlockNotRendered b)
case () of
_ | plain -> renderEmpty
| isEnabled Ext_raw_attribute opts -> rawAttribBlock
| f `elem` ["markdown", "markdown_github", "markdown_phpextra",
"markdown_mmd", "markdown_strict"] ->
return $ text str <> text "\n"
Expand All @@ -484,7 +485,6 @@ blockToMarkdown' opts b@(RawBlock f str) = do
text str <> text "\n"
| isEnabled Ext_raw_attribute opts -> rawAttribBlock
| otherwise -> renderEmpty
| isEnabled Ext_raw_attribute opts -> rawAttribBlock
| otherwise -> renderEmpty
blockToMarkdown' opts HorizontalRule = do
return $ blankline <> text (replicate (writerColumns opts) '-') <> blankline
Expand Down Expand Up @@ -1152,6 +1152,7 @@ inlineToMarkdown opts il@(RawInline f str) = do
| f `elem` ["markdown", "markdown_github", "markdown_phpextra",
"markdown_mmd", "markdown_strict"] ->
return $ text str
| isEnabled Ext_raw_attribute opts -> rawAttribInline
| f `elem` ["html", "html5", "html4"] ->
case () of
_ | isEnabled Ext_raw_html opts -> return $ text str
Expand All @@ -1162,7 +1163,6 @@ inlineToMarkdown opts il@(RawInline f str) = do
_ | isEnabled Ext_raw_tex opts -> return $ text str
| isEnabled Ext_raw_attribute opts -> rawAttribInline
| otherwise -> renderEmpty
| isEnabled Ext_raw_attribute opts -> rawAttribInline
| otherwise -> renderEmpty
inlineToMarkdown opts (LineBreak) = do
plain <- asks envPlain
Expand Down
2 changes: 1 addition & 1 deletion test/Tests/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ infix 4 =:
tests :: [TestTree]
tests = [ "indented code after list"
=: (orderedList [ para "one" <> para "two" ] <> codeBlock "test")
=?> "1. one\n\n two\n\n<!-- -->\n\n test"
=?> "1. one\n\n two\n\n```{=html}\n<!-- -->\n```\n test"
, "list with tight sublist"
=: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
plain "baz" ]
Expand Down
2 changes: 1 addition & 1 deletion test/command/4164.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is inline html:
<div>
<balise> bla bla
`<balise>`{=html} bla bla
</div>
Expand Down
10 changes: 5 additions & 5 deletions test/command/macros.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
% pandoc -f markdown+latex_macros -t markdown
% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
$\my+\my$
^D
Expand All @@ -9,7 +9,7 @@ $\phi+\phi$
```

```
% pandoc -f markdown-latex_macros -t markdown
% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
$\my+\my$
^D
Expand Down Expand Up @@ -70,7 +70,7 @@ x &= y\\\end{aligned}\]
```

```
% pandoc -f markdown+latex_macros -t markdown
% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
\begin{equation}
\my+\my
Expand All @@ -84,7 +84,7 @@ x &= y\\\end{aligned}\]
```

```
% pandoc -f markdown-latex_macros -t markdown
% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
\begin{equation}
\my+\my
Expand All @@ -98,7 +98,7 @@ x &= y\\\end{aligned}\]
```

```
% pandoc -f markdown+latex_macros -t markdown
% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\emph{a}}
\my
^D
Expand Down
4 changes: 2 additions & 2 deletions test/command/parse-raw.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
% pandoc -f latex+raw_tex -t markdown
\emph{Hi \foo{there}}
^D
*Hi \foo{there}*
*Hi `\foo{there}`{=latex}*
```

```
Expand All @@ -16,7 +16,7 @@
% pandoc -f html+raw_html -t markdown
<em>Hi <blink>there</blink></em>
^D
*Hi <blink>there</blink>*
*Hi `<blink>`{=html}there`</blink>`{=html}*
```

```
Expand Down
52 changes: 47 additions & 5 deletions test/writer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,35 @@ bar

Interpreted markdown in a table:

```{=html}
<table>
```
```{=html}
<tr>
```
```{=html}
<td>
```
This is *emphasized*
```{=html}
</td>
```
```{=html}
<td>
```
And this is **strong**
```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
```{=html}
<script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>

```
Here's a simple block:

<div>
Expand Down Expand Up @@ -447,41 +464,64 @@ foo

This should just be an HTML comment:

```{=html}
<!-- Comment -->

```
Multiline:

```{=html}
<!--
Blah
Blah
-->
```
```{=html}
<!--
This is another comment.
-->

```
Code block:

<!-- Comment -->

Just plain comment, with trailing spaces on the line:

```{=html}
<!-- foo -->

```
Code:

<hr />

Hr's:

```{=html}
<hr>
```
```{=html}
<hr />
```
```{=html}
<hr />
```
```{=html}
<hr>
```
```{=html}
<hr />
```
```{=html}
<hr />
```
```{=html}
<hr class="foo" id="bar" />
```
```{=html}
<hr class="foo" id="bar" />
```
```{=html}
<hr class="foo" id="bar">
```

------------------------------------------------------------------------------

Expand Down Expand Up @@ -540,7 +580,7 @@ Ellipses...and...and....
LaTeX
=====

- \cite[22-23]{smith.1899}
- `\cite[22-23]{smith.1899}`{=tex}
- $2+2=4$
- $x \in y$
- $\alpha \wedge \omega$
Expand All @@ -560,11 +600,13 @@ These shouldn't be math:

Here's a LaTeX table:

```{=tex}
\begin{tabular}{|l|l|}\hline
Animal & Number \\ \hline
Dog & 2 \\
Cat & 1 \\ \hline
\end{tabular}
```

------------------------------------------------------------------------------

Expand Down

0 comments on commit 28cad16

Please sign in to comment.