-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Markdown writer: Cleaner (code)blocks with single class #7242
Conversation
0938bb6
to
5f21098
Compare
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.
5f21098
to
6dc4e11
Compare
@@ -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 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.
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.
I like the space.
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.
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
Thanks! |
In jgm#7242, we introduced a simple attribute style for for code blocks and fenced divs with a single class but turns out the CommonMark extension does not support it for fenced divs. https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md
In jgm#7242, we introduced a simple attribute style for for code blocks and fenced divs with a single class but turns out the CommonMark extension does not support it for fenced divs. https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md
In jgm#7242, we introduced a simple attribute style for for code blocks and fenced divs with a single class but turns out the CommonMark extension does not support it for fenced divs. https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md
In #7242, we introduced a simple attribute style for for code blocks and fenced divs with a single class but turns out the CommonMark extension does not support it for fenced divs. https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md
-- | (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 |
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
This follows a similar change in pandoc (jgm/pandoc#7242). Closes #84.
0.2.3 * Allow bare word attribute in fenced_divs (#84). This follows a similar change in pandoc (jgm/pandoc#7242). 0.2.2.1 * Fix commonmark-extensions to build with GHC 9.2 (#81, Joseph C. Sible). Currently --allow-newer is needed. 0.2.2 * Add footnote to gfmExtensions. Note that this also requires additional type constraints on gfmExtensions [API change]. 0.2.1.2 * Fix bug with absolute paths in rebase_relative_paths extension on Windows. 0.2.1.1 * Fix bug in wikilinks extensions. 0.2.1 * Add rebase_relative_paths extension. New exported module Commonmark.Extensions.RebaseRelativePaths [API change]. * Add wikilinks_title_before_pipe and wikilinks_title_after_pipe extensions (#69). New exported module Commonmark.Extensions.Wikilinks [API change].
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.
Test