From dca55630e641905d5447b9468d0953227f9e704a Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Tue, 12 Aug 2014 23:40:51 -0400 Subject: Docx Reader: Trim line breaks from the beginning and end of Section Headers. We might also want to do this elsewhere (for pars, for example). --- src/Text/Pandoc/Readers/Docx.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 28f49251c..dcc2122bd 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -455,6 +455,13 @@ isHeaderContainer :: Container Block -> Bool isHeaderContainer (Container f) | Header _ _ _ <- f [] = True isHeaderContainer _ = False +trimLineBreaks :: [Inline] -> [Inline] +trimLineBreaks [] = [] +trimLineBreaks (LineBreak : ils) = trimLineBreaks ils +trimLineBreaks ils + | (LineBreak : ils') <- reverse ils = trimLineBreaks (reverse ils') +trimLineBreaks ils = ils + bodyPartToBlocks :: BodyPart -> DocxContext [Block] bodyPartToBlocks (Paragraph pPr parparts) | any isBlockCodeContainer (parStyleToContainers pPr) = @@ -467,8 +474,9 @@ bodyPartToBlocks (Paragraph pPr parparts) [CodeBlock ("", [], []) (concatMap parPartToString parparts)] bodyPartToBlocks (Paragraph pPr parparts) | any isHeaderContainer (parStyleToContainers pPr) = do - ils <- normalizeSpaces <$> local (\s -> s{docxInHeaderBlock = True}) - (parPartsToInlines parparts) + ils <- (trimLineBreaks . normalizeSpaces) <$> + local (\s -> s{docxInHeaderBlock = True}) + (parPartsToInlines parparts) let (Container hdrFun) = head $ filter isHeaderContainer (parStyleToContainers pPr) Header n attr _ = hdrFun [] hdr <- makeHeaderAnchor $ Header n attr ils -- cgit v1.2.3