From 71452946d9f4d76a993c6a0ff5d51c416487bcf3 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Fri, 5 Sep 2014 21:54:17 -0400 Subject: Docx reader: Use polyglot header list. We're just keeping a list of header formats that different languages use as their default styles. At the moment, we have English, German, Danish, and French. We can continue to add to this. This is simpler than parsing the styles file, and perhaps less error-prone, since there seems to be some variations, even within a language, of how a style file will define headers. --- src/Text/Pandoc/Readers/Docx.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 12b651574..6703c779d 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -85,7 +85,7 @@ import Text.Pandoc.Readers.Docx.Reducible import Text.Pandoc.Shared import Text.Pandoc.MediaBag (insertMedia, MediaBag) import Data.Maybe (isJust) -import Data.List (delete, stripPrefix, (\\), intersect) +import Data.List (delete, stripPrefix, (\\), intersect, isPrefixOf) import Data.Monoid import Text.TeXMath (writeTeX) import Data.Default (Default) @@ -471,7 +471,6 @@ bodyPartToBlocks (Paragraph pPr parparts) , Just n <- isHeaderClass c = do ils <- local (\s-> s{docxInHeaderBlock=True}) $ (concatReduce <$> mapM parPartToInlines parparts) - makeHeaderAnchor $ headerWith ("", delete ("Heading" ++ show n) cs, []) n ils | otherwise = do @@ -562,9 +561,10 @@ docxToOutput opts (Docx (Document _ body)) = evalDocxContext (bodyToOutput body) dEnv def isHeaderClass :: String -> Maybe Int -isHeaderClass s | Just s' <- stripPrefix "Heading" s = - case reads s' :: [(Int, String)] of - [] -> Nothing - ((n, "") : []) -> Just n - _ -> Nothing +isHeaderClass s | (pref:_) <- filter (\h -> isPrefixOf h s) headerPrefixes + , Just s' <- stripPrefix pref s = + case reads s' :: [(Int, String)] of + [] -> Nothing + ((n, "") : []) -> Just n + _ -> Nothing isHeaderClass _ = Nothing -- cgit v1.2.3