aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-02-16 11:14:15 -0800
committerJohn MacFarlane <[email protected]>2025-02-16 11:15:41 -0800
commitabf0b5123b5a006146efa2e9bf39297b5dc8d9ac (patch)
tree33404e63c2f972a84711e3bfe863bbba29397c77 /src
parent2d2570881b8dd7334dcc35f722379cc476140f78 (diff)
T.P.Shared, makeSections: put some attributes on section element only.
Certain `role` and `epub:type` attributes should only be on the section (and indeed, many `role`s give a validation error if left on the heading element).
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs9
-rw-r--r--src/Text/Pandoc/Writers/DocBook.hs5
2 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 1badeeb58..2c748dc5f 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -547,9 +547,14 @@ makeSectionsWithOffsets numoffsets numbering mbBaseLevel bs =
("number", T.intercalate "." (map tshow newnum)) : kvs
_ -> kvs
let divattr = (ident, "section":classes, kvs')
- let attr = ("",classes,kvs')
+ let isHeadingAttr ("epub:type",_) = False
+ isHeadingAttr ("role",v) =
+ v `elem` ["tab", "presentation", "none", "treeitem",
+ "menuitem", "button", "heading"]
+ isHeadingAttr _ = True
+ let hattr = ("",classes, filter isHeadingAttr kvs')
return $
- Div divattr (Header level' attr title' : sectionContents') : rest'
+ Div divattr (Header level' hattr title' : sectionContents') : rest'
go (Div divattr@(dident,dclasses,_) (Header level hattr title':ys) : xs)
| all (\case
Header level' _ _ -> level' > level
diff --git a/src/Text/Pandoc/Writers/DocBook.hs b/src/Text/Pandoc/Writers/DocBook.hs
index bae20c6dc..a2daf897e 100644
--- a/src/Text/Pandoc/Writers/DocBook.hs
+++ b/src/Text/Pandoc/Writers/DocBook.hs
@@ -174,7 +174,8 @@ imageToDocBook _ attr src = selfClosingTag "imagedata" $
blockToDocBook :: PandocMonad m => WriterOptions -> Block -> DB m (Doc Text)
-- Add ids to paragraphs in divs with ids - this is needed for
-- pandoc-citeproc to get link anchors in bibliographies:
-blockToDocBook opts (Div (id',"section":_,_) (Header lvl (_,classes,attrs) ils : xs)) = do
+blockToDocBook opts (Div (id',"section":_classes,divattrs)
+ (Header lvl (_,hclasses,_) ils : xs)) = do
version <- ask
-- DocBook doesn't allow sections with no content, so insert some if needed
let bs = if null xs
@@ -198,7 +199,7 @@ blockToDocBook opts (Div (id',"section":_,_) (Header lvl (_,classes,attrs) ils :
-- Populate miscAttr with Header.Attr.attributes, filtering out non-valid DocBook section attributes, id, and xml:id
-- Also enrich the role attribute with certain class tokens
- miscAttr = enrichRole (filter (isSectionAttr version) attrs) classes
+ miscAttr = enrichRole (filter (isSectionAttr version) divattrs) hclasses
attribs = nsAttr <> idAttr <> miscAttr
title' <- inlinesToDocBook opts ils
contents <- blocksToDocBook opts bs