git.iko.soy/typeable/pandoc
on master help sign in
Docx Reader: Remove header class properly in other langs

When we encounter one of the polyglot header styles, we want to remove that from the par styles after we convert to a header. To do that, we have to keep track of the style name, and remove it appropriately.

commit132814aeb68fc7f50c2ab8370339e0c5ffb7793d authorJesse Rosenthal <jrosenthal@jhu.edu> dateSat 6 Sep 2014, 07:53 (12 years ago) parentf56e0e9
1 file changed+4−4
src/Text/Pandoc/Readers/Docx.hs+4−4
src/Text/Pandoc/Readers/Docx.hs+4−4
@@ -468,11 +468,11 @@ bodyPartToBlocks (Paragraph pPr parparts)
468468 $ codeBlock
469469 $ concatMap parPartToString parparts
470470 | (c : cs) <- filter (isJust . isHeaderClass) $ pStyle pPr
471− , Just n <- isHeaderClass c = do
471+ , Just (prefix, n) <- isHeaderClass c = do
472472 ils <- local (\s-> s{docxInHeaderBlock=True}) $
473473 (concatReduce <$> mapM parPartToInlines parparts)
474474 makeHeaderAnchor $
475− headerWith ("", delete ("Heading" ++ show n) cs, []) n ils
475+ headerWith ("", delete (prefix ++ show n) cs, []) n ils
476476 | otherwise = do
477477 ils <- concatReduce <$> mapM parPartToInlines parparts >>=
478478 (return . fromList . trimLineBreaks . normalizeSpaces . toList)
@@ -560,11 +560,11 @@ docxToOutput opts (Docx (Document _ body)) =
560560 let dEnv = def { docxOptions = opts} in
561561 evalDocxContext (bodyToOutput body) dEnv def
562562
563−isHeaderClass :: String -> Maybe Int
563+isHeaderClass :: String -> Maybe (String, Int)
564564isHeaderClass s | (pref:_) <- filter (\h -> isPrefixOf h s) headerPrefixes
565565 , Just s' <- stripPrefix pref s =
566566 case reads s' :: [(Int, String)] of
567567 [] -> Nothing
568− ((n, "") : []) -> Just n
568+ ((n, "") : []) -> Just (pref, n)
569569 _ -> Nothing
570570isHeaderClass _ = Nothing