8000 Markdown writer: Cleaner (code)blocks with single class by jtojnar · Pull Request #7242 · jgm/pandoc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Markdown writer: Cleaner (code)blocks with single class #7242

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

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Text/Pandoc/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to check also for empty attributes: see #7397

classOrAttrsToMarkdown attrs = attrsToMarkdown attrs

linkAttributes :: WriterOptions -> Attr -> Doc Text
linkAttributes opts attr =
if isEnabled Ext_link_attributes opts && attr /= nullAttr
Expand Down Expand Up @@ -344,7 +350,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 ||
Expand Down Expand Up @@ -513,7 +519,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if I should keep the space in case of single class. Traditionally, there is not one.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the space.

Copy link
Contributor Author
@jtojnar jtojnar Apr 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else case attribs of
(_,cls:_,_) -> " " <> literal cls
_ -> empty
Expand Down
2 changes: 1 addition & 1 deletion test/command/5304.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
...
```
^D
``` {.markdown}
``` markdown
`«sträng»`

`` «sträng» ``
Expand Down
2 changes: 1 addition & 1 deletion test/command/5519.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
```
``````
^D
```` {.attr}
```` attr
```
code
```
Expand Down
4 changes: 2 additions & 2 deletions test/command/6925.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/command/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

## b

::: {.interior}
::: interior
# C

## cc

# D
:::

::: {.blue}
::: blue
# E

## e
Expand Down
0