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).
This commit is contained in:
Jesse Rosenthal 2014-08-12 23:40:51 -04:00
parent 378a795eaa
commit dca55630e6
2 changed files with 11 additions and 3 deletions

@ -1 +1 @@
Subproject commit 095196e8d6e873ee36846ca120bf5dfd39e30a8c
Subproject commit 3befef257ce461ae68760004df938f3ca8397b31

View file

@ -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