diff options
| author | Edwin Török <edwin@etorok.net> | 2023-12-19 20:13:41 +0000 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-12-19 15:00:23 -0800 |
| commit | 712d746320d2f2bd1ee345dfa903b8d20d359cbe (patch) | |
| tree | 85a272734ca444cc0544477447b05aa05193d183 /src | |
| parent | c6892bec243fd3c8118fa87885455a7e6ce87f78 (diff) | |
fix(docx): sort inline elements in schema order
Fixes #9273
```
[
{
"Description": "The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:b'.",
"Path": {
"NamespacesDefinitions": [
"xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\""
],
"Namespaces": {
},
"XPath": "/w:document[1]/w:body[1]/w:p[1]/w:r[7]/w:rPr[1]",
"PartUri": "/word/document.xml"
},
"Id": "Sch_UnexpectedElementContentExpectingComplex",
"ErrorType": "Schema"
}
]
```
Signed-off-by: Edwin Török <edwin@etorok.net>
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 44c0e900d..afafd6926 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -36,7 +36,8 @@ import Control.Monad.State.Strict ( StateT(runStateT), gets, modify ) import qualified Data.ByteString.Lazy as BL import Data.Containers.ListUtils (nubOrd) import Data.Char (isSpace, isLetter) -import Data.List (intercalate, isPrefixOf, isSuffixOf) +import Data.List (intercalate, isPrefixOf, isSuffixOf, sortBy) +import Data.Ord (comparing) import Data.String (fromString) import qualified Data.Map as M import Data.Maybe (fromMaybe, isNothing, mapMaybe, maybeToList, isJust) @@ -77,9 +78,63 @@ import Text.Pandoc.XML.Light as XML import Data.Generics (mkT, everywhere) import Text.Collate.Lang (renderLang, Lang(..)) +-- from wml.xsd EG_RPrBase +rPrTagOrder :: M.Map Text Int +rPrTagOrder = + M.fromList + (zip [ "rStyle" + , "rFonts" + , "b" + , "bCs" + , "i" + , "iCs" + , "caps" + , "smallCaps" + , "strike" + , "dstrike" + , "outline" + , "shadow" + , "emboss" + , "imprint" + , "noProof" + , "snapToGrid" + , "vanish" + , "webHidden" + , "color" + , "spacing" + , "w" + , "kern" + , "position" + , "sz" + , "szCs" + , "highlight" + , "u" + , "effect" + , "bdr" + , "shd" + , "fitText" + , "vertAlign" + , "rtl" + , "cs" + , "em" + , "lang" + , "eastAsianLayout" + , "specVanish" + , "oMath" + ] [0..]) + +sortSquashed :: [Element] -> [Element] +sortSquashed l = + sortBy (comparing tagIndex) l + where + tagIndex :: Element -> Int + tagIndex el = + fromMaybe 0 (M.lookup tag rPrTagOrder) + where tag = (qName . elName) el + squashProps :: EnvProps -> [Element] -squashProps (EnvProps Nothing es) = es -squashProps (EnvProps (Just e) es) = e : es +squashProps (EnvProps Nothing es) = sortSquashed es +squashProps (EnvProps (Just e) es) = sortSquashed (e : es) renumIdMap :: Int -> [Element] -> M.Map Text Text renumIdMap _ [] = M.empty |
