-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
classOrAttrsToMarkdown attrs = attrsToMarkdown attrs | ||
|
||
linkAttributes :: WriterOptions -> Attr -> Doc Text | ||
linkAttributes opts attr = | ||
if isEnabled Ext_link_attributes opts && attr /= nullAttr | ||
|
@@ -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 || | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, looks like it is just as widely supported too: https://babelmark.github.io/?text=%60%60%60+nix%0Afoo%0A%60%60%60 vs https://babelmark.github.io/?text=%60%60%60nix%0Afoo%0A%60%60%60 |
||
else case attribs of | ||
(_,cls:_,_) -> " " <> literal cls | ||
_ -> empty | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
... | ||
``` | ||
^D | ||
``` {.markdown} | ||
``` markdown | ||
`«sträng»` | ||
|
||
`` «sträng» `` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
``` | ||
`````` | ||
^D | ||
```` {.attr} | ||
```` attr | ||
``` | ||
code | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,15 @@ | |
|
||
## b | ||
|
||
::: {.interior} | ||
::: interior | ||
# C | ||
|
||
## cc | ||
|
||
# D | ||
::: | ||
|
||
::: {.blue} | ||
::: blue | ||
# E | ||
|
||
## e | ||
|
There was a problem hiding this comment.
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