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.
This commit is contained in:
John MacFarlane 2020-08-09 11:11:21 -07:00
parent a7c9a69004
commit a9da64cc3a
2 changed files with 23 additions and 11 deletions

View file

@ -339,7 +339,17 @@ getDefaultExtensions "muse" = extensionsFromList
[Ext_amuse,
Ext_auto_identifiers]
getDefaultExtensions "plain" = plainExtensions
getDefaultExtensions "gfm" = githubMarkdownExtensions
getDefaultExtensions "gfm" = extensionsFromList
[ Ext_pipe_tables
, Ext_raw_html
, Ext_native_divs
, Ext_auto_identifiers
, Ext_gfm_auto_identifiers
, Ext_autolink_bare_uris
, Ext_strikeout
, Ext_task_lists
, Ext_emoji
]
getDefaultExtensions "commonmark" = extensionsFromList
[Ext_raw_html]
getDefaultExtensions "commonmark_x" = extensionsFromList
@ -364,9 +374,7 @@ getDefaultExtensions "commonmark_x" = extensionsFromList
, Ext_raw_attribute
, Ext_implicit_header_references
, Ext_attributes
, Ext_fenced_code_blocks
, Ext_fenced_code_attributes
, Ext_backtick_code_blocks
]
getDefaultExtensions "org" = extensionsFromList
[Ext_citations,
@ -489,9 +497,7 @@ getAllExtensions f = universalExtensions <> getAll f
, Ext_raw_attribute
, Ext_implicit_header_references
, Ext_attributes
, Ext_fenced_code_blocks
, Ext_fenced_code_attributes
, Ext_backtick_code_blocks
]
getAll "commonmark_x" = getAll "commonmark"
getAll "org" = autoIdExtensions <>

View file

@ -561,9 +561,12 @@ blockToMarkdown' opts (CodeBlock (_,classes,_) str)
| "haskell" `elem` classes && "literate" `elem` classes &&
isEnabled Ext_literate_haskell opts =
return $ prefixed "> " (literal str) <> blankline
blockToMarkdown' opts (CodeBlock attribs str) = return $
case attribs == nullAttr of
False | isEnabled Ext_backtick_code_blocks opts ->
blockToMarkdown' opts (CodeBlock attribs str) = do
variant <- asks envVariant
return $
case attribs == nullAttr of
False | variant == Commonmark ||
isEnabled Ext_backtick_code_blocks opts ->
backticks <> attrs <> cr <> literal str <> cr <> backticks <> blankline
| isEnabled Ext_fenced_code_blocks opts ->
tildes <> attrs <> cr <> literal str <> cr <> tildes <> blankline
@ -856,9 +859,12 @@ blockListToMarkdown opts blocks = do
-- b) change Plain to Para unless it's followed by a RawBlock
-- or has a list as its parent (#3487)
let fixBlocks (b : CodeBlock attr x : rest)
| (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
&& isListBlock b = b : commentSep : CodeBlock attr x :
fixBlocks rest
| (not (variant == Commonmark ||
isEnabled Ext_backtick_code_blocks opts ||
isEnabled Ext_fenced_code_blocks opts) ||
attr == nullAttr)
&& isListBlock b
= b : commentSep : CodeBlock attr x : fixBlocks rest
fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
b1 : commentSep : fixBlocks (b2:bs)
fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =