mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-26 18:26:36 +00:00
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>
This commit is contained in:
committed by
John MacFarlane
parent
c6892bec24
commit
712d746320
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user