Skip to content
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

Merged
merged 1 commit into from
Apr 25, 2021

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Apr 24, 2021

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

$ printf '```nix\nfoo\n```' | cabal exec -- pandoc -f markdown -t markdown
``` nix
foo
```
$ printf ':::warning\nfoo\n:::' | cabal exec -- pandoc -f markdown -t markdown
::: warning
foo
:::

@jtojnar jtojnar force-pushed the md-simple-block-class branch 2 times, most recently from 0938bb6 to 5f21098 Compare April 24, 2021 05:40
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.
@@ -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.

@jgm jgm merged commit e9c0f9f into jgm:master Apr 25, 2021
@jgm
Copy link
Owner

jgm commented Apr 25, 2021

Thanks!

@jtojnar jtojnar deleted the md-simple-block-class branch April 25, 2021 18:06
jtojnar added a commit to jtojnar/pandoc that referenced this pull request Jun 5, 2021
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
jtojnar added a commit to jtojnar/pandoc that referenced this pull request Jun 5, 2021
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
jtojnar added a commit to jtojnar/pandoc that referenced this pull request Jun 5, 2021
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
jgm pushed a commit that referenced this pull request Jun 5, 2021
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
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

jgm added a commit that referenced this pull request Jun 21, 2021
Code blocks with a single class but nonempty attributes
were having attributes drop as a result of #7242.

Closes #7397.
ickc added a commit to ickc/pantable that referenced this pull request Jul 3, 2021
jgm added a commit to jgm/commonmark-hs that referenced this pull request Dec 31, 2021
This follows a similar change in pandoc (jgm/pandoc#7242).
Closes #84.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Feb 11, 2022
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].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants