git.iko.soy/typeable/pandoc
on master help sign in
Remove `fenced_code_blocks` and `backtick_code_blocks` from...

commonmark/gfm extensions. These shouldn't really be counted as extensions, because they can't be disabled in commonmark. Adjust markdown writer to check for commonmark variant in addition to extensions.

commita9da64cc3a7da3752f8dc3b398a8182453c934fe authorJohn MacFarlane <jgm@berkeley.edu> dateSun 9 Aug 2020, 11:11 (6 years ago) parenta7c9a69
2 files changed+23−11
src/Text/Pandoc/Extensions.hs+11−5 src/Text/Pandoc/Writers/Markdown.hs+12−6
src/Text/Pandoc/Extensions.hs+11−5
@@ -339,7 +339,17 @@ getDefaultExtensions "muse" = extensionsFromList
339339 [Ext_amuse,
340340 Ext_auto_identifiers]
341341getDefaultExtensions "plain" = plainExtensions
342−getDefaultExtensions "gfm" = githubMarkdownExtensions
342+getDefaultExtensions "gfm" = extensionsFromList
343+ [ Ext_pipe_tables
344+ , Ext_raw_html
345+ , Ext_native_divs
346+ , Ext_auto_identifiers
347+ , Ext_gfm_auto_identifiers
348+ , Ext_autolink_bare_uris
349+ , Ext_strikeout
350+ , Ext_task_lists
351+ , Ext_emoji
352+ ]
343353getDefaultExtensions "commonmark" = extensionsFromList
344354 [Ext_raw_html]
345355getDefaultExtensions "commonmark_x" = extensionsFromList
@@ -364,9 +374,7 @@ getDefaultExtensions "commonmark_x" = extensionsFromList
364374 , Ext_raw_attribute
365375 , Ext_implicit_header_references
366376 , Ext_attributes
367− , Ext_fenced_code_blocks
368377 , Ext_fenced_code_attributes
369− , Ext_backtick_code_blocks
370378 ]
371379getDefaultExtensions "org" = extensionsFromList
372380 [Ext_citations,
@@ -489,9 +497,7 @@ getAllExtensions f = universalExtensions <> getAll f
489497 , Ext_raw_attribute
490498 , Ext_implicit_header_references
491499 , Ext_attributes
492− , Ext_fenced_code_blocks
493500 , Ext_fenced_code_attributes
494− , Ext_backtick_code_blocks
495501 ]
496502 getAll "commonmark_x" = getAll "commonmark"
497503 getAll "org" = autoIdExtensions <>
src/Text/Pandoc/Writers/Markdown.hs+12−6
@@ -561,9 +561,12 @@ blockToMarkdown' opts (CodeBlock (_,classes,_) str)
561561 | "haskell" `elem` classes && "literate" `elem` classes &&
562562 isEnabled Ext_literate_haskell opts =
563563 return $ prefixed "> " (literal str) <> blankline
564−blockToMarkdown' opts (CodeBlock attribs str) = return $
565− case attribs == nullAttr of
566− False | isEnabled Ext_backtick_code_blocks opts ->
564+blockToMarkdown' opts (CodeBlock attribs str) = do
565+ variant <- asks envVariant
566+ return $
567+ case attribs == nullAttr of
568+ False | variant == Commonmark ||
569+ isEnabled Ext_backtick_code_blocks opts ->
567570 backticks <> attrs <> cr <> literal str <> cr <> backticks <> blankline
568571 | isEnabled Ext_fenced_code_blocks opts ->
569572 tildes <> attrs <> cr <> literal str <> cr <> tildes <> blankline
@@ -856,9 +859,12 @@ blockListToMarkdown opts blocks = do
856859 -- b) change Plain to Para unless it's followed by a RawBlock
857860 -- or has a list as its parent (#3487)
858861 let fixBlocks (b : CodeBlock attr x : rest)
859− | (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
860− && isListBlock b = b : commentSep : CodeBlock attr x :
861− fixBlocks rest
862+ | (not (variant == Commonmark ||
863+ isEnabled Ext_backtick_code_blocks opts ||
864+ isEnabled Ext_fenced_code_blocks opts) ||
865+ attr == nullAttr)
866+ && isListBlock b
867+ = b : commentSep : CodeBlock attr x : fixBlocks rest
862868 fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
863869 b1 : commentSep : fixBlocks (b2:bs)
864870 fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =