Skip to content

Commit

Permalink
Markdown writer: don't use raw_attribute syntax for raw...
Browse files Browse the repository at this point in the history
blocks, unless there is no other option.

Mainly this is motivated by #9677.  If we put raw tex in a
raw_attribute block, then the macros don't get interpreted
when it is read again by pandoc's markdown reader.
  • Loading branch information
jgm committed Apr 23, 2024
1 parent b37ad70 commit f5c7d4d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 51 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 @@ -474,8 +474,7 @@ blockToMarkdown' opts b@(RawBlock f str) = do
"markdown_mmd", "markdown_strict"]
-> return $ literal str <> literal "\n"
Markua -> renderEmpty
_ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
| f `elem` ["html", "html5", "html4"]
_ | f `elem` ["html", "html5", "html4"]
, isEnabled Ext_markdown_attribute opts
-> return $ literal (addMarkdownAttribute str) <> literal "\n"
| f `elem` ["html", "html5", "html4"]
Expand All @@ -484,6 +483,7 @@ blockToMarkdown' opts b@(RawBlock f str) = do
| f `elem` ["latex", "tex"]
, isEnabled Ext_raw_tex opts
-> return $ literal str <> literal "\n"
| isEnabled Ext_raw_attribute opts -> rawAttribBlock
_ -> renderEmpty
blockToMarkdown' opts HorizontalRule = do
variant <- asks envVariant
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 @@ -41,7 +41,7 @@ infix 4 =:
tests :: [TestTree]
tests = [ "indented code after list"
=: (orderedList [ para "one" <> para "two" ] <> codeBlock "test")
=?> "1. one\n\n two\n\n```{=html}\n<!-- -->\n```\n test"
=?> "1. one\n\n two\n\n<!-- -->\n\n test"
, "list with tight sublist"
=: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
plain "baz" ]
Expand Down
50 changes: 4 additions & 46 deletions test/writer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -383,35 +383,18 @@ 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 @@ -448,64 +431,41 @@ 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 @@ -581,13 +541,11 @@ 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
4 changes: 2 additions & 2 deletions test/writer.opml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
</outline>
<outline text="Definition Lists" _note="Tight using spaces:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Tight using tabs:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;banana&#10;&#10;: yellow fruit&#10;&#10;Multiple blocks with italics:&#10;&#10;*apple*&#10;&#10;: red fruit&#10;&#10; contains seeds, crisp, pleasant to taste&#10;&#10;*orange*&#10;&#10;: orange fruit&#10;&#10; { orange code block }&#10;&#10; &gt; orange block quote&#10;&#10;Multiple definitions, tight:&#10;&#10;apple&#10;: red fruit&#10;: computer&#10;&#10;orange&#10;: orange fruit&#10;: bank&#10;&#10;Multiple definitions, loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;: bank&#10;&#10;Blank line after term, indented marker, alternate markers:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10; 1. sublist&#10; 2. sublist">
</outline>
<outline text="HTML Blocks" _note="Simple block on one line:&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;And nested without indentation:&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;bar&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;Interpreted markdown in a table:&#10;&#10;```{=html}&#10;&lt;table&gt;&#10;```&#10;```{=html}&#10;&lt;tr&gt;&#10;```&#10;```{=html}&#10;&lt;td&gt;&#10;```&#10;This is *emphasized*&#10;```{=html}&#10;&lt;/td&gt;&#10;```&#10;```{=html}&#10;&lt;td&gt;&#10;```&#10;And this is **strong**&#10;```{=html}&#10;&lt;/td&gt;&#10;```&#10;```{=html}&#10;&lt;/tr&gt;&#10;```&#10;```{=html}&#10;&lt;/table&gt;&#10;```&#10;```{=html}&#10;&lt;script type=&quot;text/javascript&quot;&gt;document.write('This *should not* be interpreted as markdown');&lt;/script&gt;&#10;```&#10;Here's a simple block:&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;This should be a code block, though:&#10;&#10; &lt;div&gt;&#10; foo&#10; &lt;/div&gt;&#10;&#10;As should this:&#10;&#10; &lt;div&gt;foo&lt;/div&gt;&#10;&#10;Now, nested:&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;This should just be an HTML comment:&#10;&#10;```{=html}&#10;&lt;!-- Comment --&gt;&#10;```&#10;Multiline:&#10;&#10;```{=html}&#10;&lt;!--&#10;Blah&#10;Blah&#10;--&gt;&#10;```&#10;```{=html}&#10;&lt;!--&#10; This is another comment.&#10;--&gt;&#10;```&#10;Code block:&#10;&#10; &lt;!-- Comment --&gt;&#10;&#10;Just plain comment, with trailing spaces on the line:&#10;&#10;```{=html}&#10;&lt;!-- foo --&gt;&#10;```&#10;Code:&#10;&#10; &lt;hr /&gt;&#10;&#10;Hr's:&#10;&#10;```{=html}&#10;&lt;hr&gt;&#10;```&#10;```{=html}&#10;&lt;hr /&gt;&#10;```&#10;```{=html}&#10;&lt;hr /&gt;&#10;```&#10;```{=html}&#10;&lt;hr&gt;&#10;```&#10;```{=html}&#10;&lt;hr /&gt;&#10;```&#10;```{=html}&#10;&lt;hr /&gt;&#10;```&#10;```{=html}&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;```&#10;```{=html}&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;```&#10;```{=html}&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot;&gt;&#10;```&#10;&#10;--------------------------------------------------------------------------------">
<outline text="HTML Blocks" _note="Simple block on one line:&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;And nested without indentation:&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;bar&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;Interpreted markdown in a table:&#10;&#10;&lt;table&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&#10;This is *emphasized*&#10;&lt;/td&gt;&#10;&lt;td&gt;&#10;And this is **strong**&#10;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/table&gt;&#10;&lt;script type=&quot;text/javascript&quot;&gt;document.write('This *should not* be interpreted as markdown');&lt;/script&gt;&#10;&#10;Here's a simple block:&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;This should be a code block, though:&#10;&#10; &lt;div&gt;&#10; foo&#10; &lt;/div&gt;&#10;&#10;As should this:&#10;&#10; &lt;div&gt;foo&lt;/div&gt;&#10;&#10;Now, nested:&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;&lt;div&gt;&#10;&#10;foo&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;&lt;/div&gt;&#10;&#10;This should just be an HTML comment:&#10;&#10;&lt;!-- Comment --&gt;&#10;&#10;Multiline:&#10;&#10;&lt;!--&#10;Blah&#10;Blah&#10;--&gt;&#10;&lt;!--&#10; This is another comment.&#10;--&gt;&#10;&#10;Code block:&#10;&#10; &lt;!-- Comment --&gt;&#10;&#10;Just plain comment, with trailing spaces on the line:&#10;&#10;&lt;!-- foo --&gt;&#10;&#10;Code:&#10;&#10; &lt;hr /&gt;&#10;&#10;Hr's:&#10;&#10;&lt;hr&gt;&#10;&lt;hr /&gt;&#10;&lt;hr /&gt;&#10;&lt;hr&gt;&#10;&lt;hr /&gt;&#10;&lt;hr /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot;&gt;&#10;&#10;--------------------------------------------------------------------------------">
</outline>
<outline text="Inline Markup" _note="This is *emphasized*, and so *is this*.&#10;&#10;This is **strong**, and so **is this**.&#10;&#10;An *[emphasized link](/url)*.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;This is code: `&gt;`, `$`, `\`, `\$`, `&lt;html&gt;`.&#10;&#10;~~This is *strikeout*.~~&#10;&#10;Superscripts: a^bc^d a^*hello*^ a^hello there^.&#10;&#10;Subscripts: H~2~O, H~23~O, H~many of them~O.&#10;&#10;These should not be superscripts or subscripts, because of the unescaped spaces:&#10;a\^b c\^d, a\~b c\~d.&#10;&#10;--------------------------------------------------------------------------------">
</outline>
<outline text="Smart quotes, ellipses, dashes" _note="&quot;Hello,&quot; said the spider. &quot;'Shelob' is my name.&quot;&#10;&#10;'A', 'B', and 'C' are letters.&#10;&#10;'Oak,' 'elm,' and 'beech' are names of trees. So is 'pine.'&#10;&#10;'He said, &quot;I want to go.&quot;' Were you alive in the 70's?&#10;&#10;Here is some quoted '`code`' and a &quot;[quoted&#10;link](http://example.com/?foo=1&amp;bar=2)&quot;.&#10;&#10;Some dashes: one---two --- three---four --- five.&#10;&#10;Dashes between numbers: 5--7, 255--66, 1987--1999.&#10;&#10;Ellipses...and...and....&#10;&#10;--------------------------------------------------------------------------------">
</outline>
<outline text="LaTeX" _note="- `\cite[22-23]{smith.1899}`{=tex}&#10;- $2+2=4$&#10;- $x \in y$&#10;- $\alpha \wedge \omega$&#10;- $223$&#10;- $p$-Tree&#10;- Here's some display math:&#10; $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$&#10;- Here's one that has a line break in it: $\alpha + \omega \times x^2$.&#10;&#10;These shouldn't be math:&#10;&#10;- To get the famous equation, write `$e = mc^2$`.&#10;- \$22,000 is a *lot* of money. So is \$34,000. (It worked if &quot;lot&quot; is&#10; emphasized.)&#10;- Shoes (\$20) and socks (\$5).&#10;- Escaped `$`: \$73 *this should be emphasized* 23\$.&#10;&#10;Here's a LaTeX table:&#10;&#10;```{=tex}&#10;\begin{tabular}{|l|l|}\hline&#10;Animal &amp; Number \\ \hline&#10;Dog &amp; 2 \\&#10;Cat &amp; 1 \\ \hline&#10;\end{tabular}&#10;```&#10;&#10;--------------------------------------------------------------------------------">
<outline text="LaTeX" _note="- `\cite[22-23]{smith.1899}`{=tex}&#10;- $2+2=4$&#10;- $x \in y$&#10;- $\alpha \wedge \omega$&#10;- $223$&#10;- $p$-Tree&#10;- Here's some display math:&#10; $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$&#10;- Here's one that has a line break in it: $\alpha + \omega \times x^2$.&#10;&#10;These shouldn't be math:&#10;&#10;- To get the famous equation, write `$e = mc^2$`.&#10;- \$22,000 is a *lot* of money. So is \$34,000. (It worked if &quot;lot&quot; is&#10; emphasized.)&#10;- Shoes (\$20) and socks (\$5).&#10;- Escaped `$`: \$73 *this should be emphasized* 23\$.&#10;&#10;Here's a LaTeX table:&#10;&#10;\begin{tabular}{|l|l|}\hline&#10;Animal &amp; Number \\ \hline&#10;Dog &amp; 2 \\&#10;Cat &amp; 1 \\ \hline&#10;\end{tabular}&#10;&#10;--------------------------------------------------------------------------------">
</outline>
<outline text="Special Characters" _note="Here is some unicode:&#10;&#10;- I hat: Î&#10;- o umlaut: ö&#10;- section: §&#10;- set membership: ∈&#10;- copyright: ©&#10;&#10;AT&amp;T has an ampersand in their name.&#10;&#10;AT&amp;T is another way to write it.&#10;&#10;This &amp; that.&#10;&#10;4 \&lt; 5.&#10;&#10;6 \&gt; 5.&#10;&#10;Backslash: \\&#10;&#10;Backtick: \`&#10;&#10;Asterisk: \*&#10;&#10;Underscore: \_&#10;&#10;Left brace: {&#10;&#10;Right brace: }&#10;&#10;Left bracket: \[&#10;&#10;Right bracket: \]&#10;&#10;Left paren: (&#10;&#10;Right paren: )&#10;&#10;Greater-than: \&gt;&#10;&#10;Hash: \#&#10;&#10;Period: .&#10;&#10;Bang: !&#10;&#10;Plus: +&#10;&#10;Minus: -&#10;&#10;--------------------------------------------------------------------------------">
</outline>
Expand Down

0 comments on commit f5c7d4d

Please sign in to comment.