Markdown writer: Cleaner (code)blocks with single class (#7242)
When a block only has a single class and no other attributes, it is not necessary to wrap the class attribute in curly braces – the class name can be placed after the opening mark as is. This will result in bit cleaner output when pandoc is used as a markdown pretty-printer.
This commit is contained in:
parent
547bc2cdf8
commit
e9c0f9f97b
5 changed files with 14 additions and 8 deletions
|
@ -278,6 +278,12 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
|
|||
escAttrChar '\\' = literal "\\\\"
|
||||
escAttrChar c = literal $ T.singleton c
|
||||
|
||||
-- | (Code) blocks with a single class can just use it standalone,
|
||||
-- no need to bother with curly braces.
|
||||
classOrAttrsToMarkdown :: Attr -> Doc Text
|
||||
classOrAttrsToMarkdown ("",[cls],_) = literal cls
|
||||
classOrAttrsToMarkdown attrs = attrsToMarkdown attrs
|
||||
|
||||
linkAttributes :: WriterOptions -> Attr -> Doc Text
|
||||
linkAttributes opts attr =
|
||||
if isEnabled Ext_link_attributes opts && attr /= nullAttr
|
||||
|
@ -343,7 +349,7 @@ blockToMarkdown' opts (Div attrs ils) = do
|
|||
case () of
|
||||
_ | isEnabled Ext_fenced_divs opts &&
|
||||
attrs /= nullAttr ->
|
||||
nowrap (literal ":::" <+> attrsToMarkdown attrs) $$
|
||||
nowrap (literal ":::" <+> classOrAttrsToMarkdown attrs) $$
|
||||
chomp contents $$
|
||||
literal ":::" <> blankline
|
||||
| isEnabled Ext_native_divs opts ||
|
||||
|
@ -512,7 +518,7 @@ blockToMarkdown' opts (CodeBlock attribs str) = do
|
|||
backticks = endline '`'
|
||||
tildes = endline '~'
|
||||
attrs = if isEnabled Ext_fenced_code_attributes opts
|
||||
then nowrap $ " " <> attrsToMarkdown attribs
|
||||
then nowrap $ " " <> classOrAttrsToMarkdown attribs
|
||||
else case attribs of
|
||||
(_,cls:_,_) -> " " <> literal cls
|
||||
_ -> empty
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
...
|
||||
```
|
||||
^D
|
||||
``` {.markdown}
|
||||
``` markdown
|
||||
`«sträng»`
|
||||
|
||||
`` «sträng» ``
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
```
|
||||
``````
|
||||
^D
|
||||
```` {.attr}
|
||||
```` attr
|
||||
```
|
||||
code
|
||||
```
|
||||
|
|
|
@ -20,13 +20,13 @@ a
|
|||
\end{thm2}
|
||||
\end{document}
|
||||
^D
|
||||
::: {.thm}
|
||||
::: thm
|
||||
**Theorem 1**. *a*
|
||||
|
||||
![image](1.png)
|
||||
:::
|
||||
|
||||
::: {.thm2}
|
||||
::: thm2
|
||||
**Theorem 1**. a
|
||||
|
||||
![image](1.png)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
## b
|
||||
|
||||
::: {.interior}
|
||||
::: interior
|
||||
# C
|
||||
|
||||
## cc
|
||||
|
@ -39,7 +39,7 @@
|
|||
# D
|
||||
:::
|
||||
|
||||
::: {.blue}
|
||||
::: blue
|
||||
# E
|
||||
|
||||
## e
|
||||
|
|
Loading…
Add table
Reference in a new issue