git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: keep h1 tags as normal headers (#7274)

The tags `<title>` and `<h1 class="title">` often contain the same information, so the latter was dropped from the document. However, as this can lead to loss of information, the heading is now always retained. Use `--shift-heading-level-by=-1` to turn the `<h1>` into the document title, or a filter to restore the previous behavior. Closes: #2293

commit013e4a3164115bf84f3e1964f21b7cd7f020b86a authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 14 May 2021, 21:31 (5 years ago) parent247b1cd
2 files changed+3−6
src/Text/Pandoc/Readers/HTML.hs+1−5 test/html-reader.native+2−1
src/Text/Pandoc/Readers/HTML.hs+1−5
@@ -499,17 +499,13 @@ pHeader = try $ do
499499 tagOpen (`elem` ["h1","h2","h3","h4","h5","h6"])
500500 (const True)
501501 let attr = toStringAttr attr'
502− let bodyTitle = TagOpen tagtype attr' ~== TagOpen ("h1" :: Text)
503− [("class","title")]
504502 level <- headerLevel tagtype
505503 contents <- trimInlines . mconcat <$> manyTill inline (pCloses tagtype <|> eof)
506504 let ident = fromMaybe "" $ lookup "id" attr
507505 let classes = maybe [] T.words $ lookup "class" attr
508506 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
509507 attr'' <- registerHeader (ident, classes, keyvals) contents
510− return $ if bodyTitle
511− then mempty -- skip a representation of the title in the body
512− else B.headerWith attr'' level contents
508+ return $ B.headerWith attr'' level contents
513509
514510pHrule :: PandocMonad m => TagParser m Blocks
515511pHrule = do
test/html-reader.native+2−1
@@ -1,5 +1,6 @@
11Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
2−[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
2+[Header 1 ("pandoc-test-suite",["title"],[]) [Str "Pandoc",Space,Str "Test",Space,Str "Suite"]
3+,Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
34,HorizontalRule
45,Header 1 ("headers",[],[]) [Str "Headers"]
56,Header 2 ("level-2-with-an-embedded-link",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Str "an",Space,Link ("",[],[]) [Str "embedded",Space,Str "link"] ("/url","")]