aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-02-12 10:01:51 -0800
committerJohn MacFarlane <[email protected]>2024-02-12 10:05:36 -0800
commitbf674e8ddd1ddb78d6300f362a3cd98ac9382b8a (patch)
tree0feae5e512b70fc6a441f699e5d8b1932a2a6e20 /src
parentbd352e41d6e34aafd5a320562829c419070163ac (diff)
Markdown writer: use different width fences for nested divs.
Outer divs have longer fences. This aids clarity for the reader, making it easier to see where the div ends. It also makes the output compatible with some other implementations, e.g. micromark, which require different-width fences for nesting. Closes #9450.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 6338a90cd..941557e0e 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -401,9 +401,12 @@ blockToMarkdown' opts (Div attrs@(_,classes,_) bs)
let attrsToMd = if variant == Commonmark
then attrsToMarkdown opts
else classOrAttrsToMarkdown opts
- in nowrap (literal ":::" <+> attrsToMd attrs) $$
+ divNesting = computeDivNestingLevel bs
+ numcolons = 3 + divNesting
+ colons = literal $ T.replicate numcolons ":"
+ in nowrap (colons <+> attrsToMd attrs) $$
chomp contents $$
- literal ":::" <> blankline
+ colons <> blankline
| isEnabled Ext_native_divs opts ||
(isEnabled Ext_raw_html opts &&
(variant == Commonmark ||
@@ -895,3 +898,9 @@ removeBlankLinesInHTML = T.pack . go False . T.unpack
go !afternewline (!c:cs)
| isSpace c = c : go afternewline cs
| otherwise = c : go False cs
+
+computeDivNestingLevel :: [Block] -> Int
+computeDivNestingLevel = foldr go 0
+ where
+ go (Div _ bls') n = max (n + 1) (foldr go (n + 1) bls')
+ go _ n = n