summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-08-09 11:36:32 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-08-09 11:36:32 -0700
commite611edb7d86af665830a34bb3ee2ff049eda0976 (patch)
tree08878da4c2ed559a9750c998c2b57ca4fd2e64d4
parentfb47bde3a30f2613b76fe6c9148e6d48581ab33b (diff)
HTML reader: avoid duplicate id on header and div.
Closes #8991.
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs8
-rw-r--r--test/command/7884.md2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 3ef95e020..5e4c8d315 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -69,6 +69,7 @@ import Text.Pandoc.Shared (
import Text.Pandoc.URI (escapeURI)
import Text.Pandoc.Walk
import Text.TeXMath (readMathML, writeTeX)
+import qualified Data.Sequence as Seq
-- | Convert HTML-formatted string to 'Pandoc' document.
readHtml :: (PandocMonad m, ToSources a)
@@ -459,13 +460,18 @@ pDiv = try $ do
TagOpen tag attr' <- lookAhead $ pSatisfy $ tagOpen isDivLike (const True)
let (ident, classes, kvs) = toAttr attr'
contents <- pInTags tag block
+ let contents' = case B.unMany contents of
+ Header lev (hident,hclasses,hkvs) ils Seq.:<| rest
+ | hident == ident ->
+ B.Many $ Header lev ("",hclasses,hkvs) ils Seq.<| rest
+ _ -> contents
let classes' = if tag == "section"
then "section":classes
else classes
kvs' = if tag == "main" && isNothing (lookup "role" kvs)
then ("role", "main"):kvs
else kvs
- return $ B.divWith (ident, classes', kvs') contents
+ return $ B.divWith (ident, classes', kvs') contents'
pIframe :: PandocMonad m => TagParser m Blocks
pIframe = try $ do
diff --git a/test/command/7884.md b/test/command/7884.md
index be410801a..d6006a831 100644
--- a/test/command/7884.md
+++ b/test/command/7884.md
@@ -22,7 +22,7 @@
)
[ Header
1
- ( "chapter-1" , [] , [ ( "number" , "1" ) ] )
+ ( "" , [] , [ ( "number" , "1" ) ] )
[ Str "Chapter" , Space , Str "1" ]
, Para
[ Str "Here"