From edd48fceb14a9b4df27d35e2ac5face06a498a67 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 22 Jul 2025 20:43:48 -0700 Subject: Djot writer: fix duplicate attributes before section headings. Closes #10984. --- src/Text/Pandoc/Writers/Djot.hs | 9 ++++++--- test/command/10984.md | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/command/10984.md 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 +

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 +

Introduction

+^D +## Introduction +``` -- cgit v1.2.3