git.iko.soy/typeable/pandoc
on master help sign in
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.

commit71452946d9f4d76a993c6a0ff5d51c416487bcf3 authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 5 Sep 2014, 21:54 (12 years ago) parent13fefd7
1 file changed+7−7
src/Text/Pandoc/Readers/Docx.hs+7−7
src/Text/Pandoc/Readers/Docx.hs+7−7
@@ -85,7 +85,7 @@ import Text.Pandoc.Readers.Docx.Reducible
8585import Text.Pandoc.Shared
8686import Text.Pandoc.MediaBag (insertMedia, MediaBag)
8787import Data.Maybe (isJust)
88−import Data.List (delete, stripPrefix, (\\), intersect)
88+import Data.List (delete, stripPrefix, (\\), intersect, isPrefixOf)
8989import Data.Monoid
9090import Text.TeXMath (writeTeX)
9191import Data.Default (Default)
@@ -471,7 +471,6 @@ bodyPartToBlocks (Paragraph pPr parparts)
471471 , Just n <- isHeaderClass c = do
472472 ils <- local (\s-> s{docxInHeaderBlock=True}) $
473473 (concatReduce <$> mapM parPartToInlines parparts)
474−
475474 makeHeaderAnchor $
476475 headerWith ("", delete ("Heading" ++ show n) cs, []) n ils
477476 | otherwise = do
@@ -562,9 +561,10 @@ docxToOutput opts (Docx (Document _ body)) =
562561 evalDocxContext (bodyToOutput body) dEnv def
563562
564563isHeaderClass :: String -> Maybe Int
565−isHeaderClass s | Just s' <- stripPrefix "Heading" s =
566− case reads s' :: [(Int, String)] of
567− [] -> Nothing
568− ((n, "") : []) -> Just n
569− _ -> Nothing
564+isHeaderClass s | (pref:_) <- filter (\h -> isPrefixOf h s) headerPrefixes
565+ , Just s' <- stripPrefix pref s =
566+ case reads s' :: [(Int, String)] of
567+ [] -> Nothing
568+ ((n, "") : []) -> Just n
569+ _ -> Nothing
570570isHeaderClass _ = Nothing