@@ -202,17 +202,30 @@ runStyleToContainers rPr =
202202 [Container $ (\ils -> Code ("", [], []) (concatMap ilToCode ils))]
203203 spanClassToContainers s | s `elem` spansToKeep =
204204 [Container $ Span ("", [s], [])]
205− spanClassToContainers _ = []
205+ spanClassToContainers _ = []
206206
207207 classContainers = case rStyle rPr of
208208 Nothing -> []
209209 Just s -> spanClassToContainers s
210210
211+ resolveFmt :: Bool -> Maybe Bool -> Bool
212+ resolveFmt _ (Just True) = True
213+ resolveFmt _ (Just False) = False
214+ resolveFmt bool Nothing = bool
215+
211216 formatters = map Container $ mapMaybe id
212− [ if isBold rPr then (Just Strong) else Nothing
213− , if isItalic rPr then (Just Emph) else Nothing
214− , if isSmallCaps rPr then (Just SmallCaps) else Nothing
215− , if isStrike rPr then (Just Strikeout) else Nothing
217+ [ if resolveFmt (rStyle rPr == Just "Bold") (isBold rPr)
218+ then (Just Strong)
219+ else Nothing
220+ , if resolveFmt (rStyle rPr == Just "Italic") (isItalic rPr)
221+ then (Just Emph)
222+ else Nothing
223+ , if resolveFmt False (isSmallCaps rPr)
224+ then (Just SmallCaps)
225+ else Nothing
226+ , if resolveFmt False (isStrike rPr)
227+ then (Just Strikeout)
228+ else Nothing
216229 , if isSuperScript rPr then (Just Superscript) else Nothing
217230 , if isSubScript rPr then (Just Subscript) else Nothing
218231 , rUnderline rPr >>=
@@ -272,7 +285,7 @@ codeSpans :: [String]
272285codeSpans = ["VerbatimChar"]
273286
274287blockQuoteDivs :: [String]
275−blockQuoteDivs = ["Quote", "BlockQuote"]
288+blockQuoteDivs = ["Quote", "BlockQuote", "BlockQuotation"]
276289
277290codeDivs :: [String]
278291codeDivs = ["SourceCode"]
@@ -389,8 +402,7 @@ parPartToInlines (PlainOMath exps) = do
389402
390403
391404isAnchorSpan :: Inline -> Bool
392−isAnchorSpan (Span (ident, classes, kvs) ils) =
393− (not . null) ident &&
405+isAnchorSpan (Span (_, classes, kvs) ils) =
394406 classes == ["anchor"] &&
395407 null kvs &&
396408 null ils
@@ -403,14 +415,16 @@ makeHeaderAnchor :: Block -> DocxContext Block
403415-- If there is an anchor already there (an anchor span in the header,
404416-- to be exact), we rename and associate the new id with the old one.
405417makeHeaderAnchor (Header n (_, classes, kvs) ils)
406− | (x : xs) <- filter isAnchorSpan ils
407− , (Span (ident, _, _) _) <- x
408− , notElem ident dummyAnchors =
418+ | xs <- filter isAnchorSpan ils
419+ , idents <- filter (\i -> notElem i dummyAnchors) $
420+ map (\(Span (ident, _, _) _) -> ident) xs
421+ , not $ null idents =
409422 do
410423 hdrIDMap <- gets docxAnchorMap
411424 let newIdent = uniqueIdent ils (M.elems hdrIDMap)
412− modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
413− return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
425+ newMap = M.fromList $ map (\i -> (i, newIdent)) idents
426+ modify $ \s -> s {docxAnchorMap = M.union newMap hdrIDMap}
427+ return $ Header n (newIdent, classes, kvs) (ils \\ xs)
414428-- Otherwise we just give it a name, and register that name (associate
415429-- it with itself.)
416430makeHeaderAnchor (Header n (_, classes, kvs) ils) =
@@ -441,6 +455,13 @@ isHeaderContainer :: Container Block -> Bool
441455isHeaderContainer (Container f) | Header _ _ _ <- f [] = True
442456isHeaderContainer _ = False
443457
458+trimLineBreaks :: [Inline] -> [Inline]
459+trimLineBreaks [] = []
460+trimLineBreaks (LineBreak : ils) = trimLineBreaks ils
461+trimLineBreaks ils
462+ | (LineBreak : ils') <- reverse ils = trimLineBreaks (reverse ils')
463+trimLineBreaks ils = ils
464+
444465bodyPartToBlocks :: BodyPart -> DocxContext [Block]
445466bodyPartToBlocks (Paragraph pPr parparts)
446467 | any isBlockCodeContainer (parStyleToContainers pPr) =
@@ -453,8 +474,9 @@ bodyPartToBlocks (Paragraph pPr parparts)
453474 [CodeBlock ("", [], []) (concatMap parPartToString parparts)]
454475bodyPartToBlocks (Paragraph pPr parparts)
455476 | any isHeaderContainer (parStyleToContainers pPr) = do
456− ils <- normalizeSpaces <$> local (\s -> s{docxInHeaderBlock = True})
457− (parPartsToInlines parparts)
477+ ils <- (trimLineBreaks . normalizeSpaces) <$>
478+ local (\s -> s{docxInHeaderBlock = True})
479+ (parPartsToInlines parparts)
458480 let (Container hdrFun) = head $ filter isHeaderContainer (parStyleToContainers pPr)
459481 Header n attr _ = hdrFun []
460482 hdr <- makeHeaderAnchor $ Header n attr ils