aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2014-09-05 21:54:17 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2014-09-05 21:59:58 -0400
commit71452946d9f4d76a993c6a0ff5d51c416487bcf3 (patch)
treea743738dff3cd50007a5953bf1e15f73301891eb
parent13fefd79597143be6629ed6e1494f54d95a80a2d (diff)
downloadpandoc-71452946d9f4d76a993c6a0ff5d51c416487bcf3.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs14
1 files changed, 7 insertions, 7 deletions
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