aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-07-22 20:43:48 -0700
committerJohn MacFarlane <[email protected]>2025-07-22 20:44:19 -0700
commitedd48fceb14a9b4df27d35e2ac5face06a498a67 (patch)
tree37143ffb8c4f1c5922135bf077c936862cbf4db5
parenta45878ff1ecb1af4a508833c05f0922f6ef28498 (diff)
Djot writer: fix duplicate attributes before section headings.
Closes #10984.
-rw-r--r--src/Text/Pandoc/Writers/Djot.hs9
-rw-r--r--test/command/10984.md16
2 files changed, 22 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Djot.hs b/src/Text/Pandoc/Writers/Djot.hs
index 45ea729eb..c7e846735 100644
--- a/src/Text/Pandoc/Writers/Djot.hs
+++ b/src/Text/Pandoc/Writers/Djot.hs
@@ -100,7 +100,8 @@ blockToDjot (BlockQuote bls) = D.blockQuote <$> blocksToDjot bls
blockToDjot (Header lev attr ils) =
fmap (D.addAttr (toDjotAttr attr)) . D.heading lev <$> inlinesToDjot ils
blockToDjot HorizontalRule = pure D.thematicBreak
-blockToDjot (Div (ident,"section":cls,kvs) bls@(Header _ _ ils : _)) = do
+blockToDjot (Div (ident,"section":cls,kvs)
+ (Header lev (_,hcls,hkvs) ils : bls)) = do
ilsBs <- D.inlinesToByteString <$> inlinesToDjot ils
let ident' = toIdentifier ilsBs
let label = D.normalizeLabel ilsBs
@@ -112,8 +113,10 @@ blockToDjot (Div (ident,"section":cls,kvs) bls@(Header _ _ ils : _)) = do
fmap
(D.addAttr (toDjotAttr (if autoid then "" else ident,
filter (/= "section") cls,
- filter (\(k,_) -> k /= "wrapper") kvs))) . D.section
- <$> blocksToDjot bls
+ filter (\(k,_) -> k /= "wrapper") kvs) <>
+ toDjotAttr ("", [c | c <- hcls, c `notElem` cls], hkvs)))
+ . D.section
+ <$> blocksToDjot (Header lev mempty ils : bls)
blockToDjot (Div attr@(ident,cls,kvs) bls)
| Just "1" <- lookup "wrapper" kvs
= fmap (D.addAttr
diff --git a/test/command/10984.md b/test/command/10984.md
new file mode 100644
index 000000000..b718d959d
--- /dev/null
+++ b/test/command/10984.md
@@ -0,0 +1,16 @@
+ ```
+ % pandoc -f html -t djot
+<h1 id="foo" class="a b">Hi</hi>
+^D
+{#foo .a .b}
+# Hi
+```
+
+In this one the id is suppressed by the djot writer because
+the same one would be automatically generated by the djot reader:
+```
+% pandoc -f html -t djot
+<h2 id="Introduction">Introduction</h2>
+^D
+## Introduction
+```