aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/FB2.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-09-07 11:23:12 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-09-08 22:20:19 -0700
commit9f984ff26ac248a27212a37ab34754a2e9261e8c (patch)
tree642ee7fb050587af729fa2585b1c97df510c9d58 /src/Text/Pandoc/Writers/FB2.hs
parent1ccff3339d036db046f37c596bb4ffb6cffbf803 (diff)
downloadpandoc-9f984ff26ac248a27212a37ab34754a2e9261e8c.tar.gz
Replace Element and makeHierarchical with makeSections.
Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`.
Diffstat (limited to 'src/Text/Pandoc/Writers/FB2.hs')
-rw-r--r--src/Text/Pandoc/Writers/FB2.hs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs
index d2527a0a9..744eb2a06 100644
--- a/src/Text/Pandoc/Writers/FB2.hs
+++ b/src/Text/Pandoc/Writers/FB2.hs
@@ -39,9 +39,9 @@ import qualified Text.Pandoc.Class as P
import Text.Pandoc.Definition
import Text.Pandoc.Logging
import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..), def)
-import Text.Pandoc.Shared (capitalize, isURI, orderedListMarkers, hierarchicalize)
+import Text.Pandoc.Shared (capitalize, isURI, orderedListMarkers,
+ makeSections)
import Text.Pandoc.Writers.Shared (lookupMetaString)
-import qualified Text.Pandoc.Shared as Shared (Element(Blk, Sec))
-- | Data to be written at the end of the document:
-- (foot)notes, URLs, references, images.
@@ -162,28 +162,27 @@ docdate meta' = do
-- representation.
renderSections :: PandocMonad m => Int -> [Block] -> FBM m [Content]
renderSections level blocks = do
- let elements = hierarchicalize blocks
- let isSection Shared.Sec{} = True
+ let blocks' = makeSections False Nothing blocks
+ let isSection (Div (_,"section":_,_) (Header{}:_)) = True
isSection _ = False
- let (initialBlocks, secs) = break isSection elements
- let elements' = if null initialBlocks
- then secs
- else Shared.Sec 1 [] nullAttr mempty initialBlocks : secs
- cMapM (renderSection level) elements'
-
-
-
-renderSection :: PandocMonad m => Int -> Shared.Element -> FBM m [Content]
-renderSection _ (Shared.Blk block) = blockToXml block
-renderSection lvl (Shared.Sec _ _num (id',_,_) title elements) = do
- content <- cMapM (renderSection (lvl + 1)) elements
+ let (initialBlocks, secs) = break isSection blocks'
+ let blocks'' = if null initialBlocks
+ then blocks'
+ else Div ("",["section"],[])
+ (Header 1 nullAttr mempty : initialBlocks) : secs
+ cMapM (renderSection level) blocks''
+
+renderSection :: PandocMonad m => Int -> Block -> FBM m [Content]
+renderSection lvl (Div (id',"section":_,_) (Header _ _ title : xs)) = do
title' <- if null title
then return []
else list . el "title" <$> formatTitle title
+ content <- cMapM (renderSection (lvl + 1)) xs
let sectionContent = if null id'
then el "section" (title' ++ content)
else el "section" ([uattr "id" id'], title' ++ content)
return [sectionContent]
+renderSection _ b = blockToXml b
-- | Only <p> and <empty-line> are allowed within <title> in FB2.
formatTitle :: PandocMonad m => [Inline] -> FBM m [Content]
@@ -334,7 +333,7 @@ blockToXml (DefinitionList defs) =
t <- wrap "strong" term
return (el "p" t : items)
blockToXml h@Header{} = do
- -- should not occur after hierarchicalize, except inside lists/blockquotes
+ -- should not occur after makeSections, except inside lists/blockquotes
report $ BlockNotRendered h
return []
blockToXml HorizontalRule = return [ el "empty-line" () ]