git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Parse nested smart tags.

Make unwrapSDT into a general `unwrap` function that can unwrap both nested SDT tags and smartTags. This makes the SmartTags constructor in the Docx type unnecessary, so we remove it. Closes #4446

commitb3fe95d7219c27233792361e4e423123cdf6a256 authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 13 Mar 2018, 14:22 (9 years ago) parent17725a0
2 files changed+11−16
src/Text/Pandoc/Readers/Docx.hs−2 src/Text/Pandoc/Readers/Docx/Parse.hs+11−14
src/Text/Pandoc/Readers/Docx.hs−2
@@ -460,8 +460,6 @@ parPartToInlines' (ExternalHyperLink target runs) = do
460460 return $ link target "" ils
461461parPartToInlines' (PlainOMath exps) =
462462 return $ math $ writeTeX exps
463−parPartToInlines' (SmartTag runs) =
464− smushInlines <$> mapM runToInlines runs
465463parPartToInlines' (Field info runs) =
466464 case info of
467465 HyperlinkField url -> parPartToInlines' $ ExternalHyperLink url runs
src/Text/Pandoc/Readers/Docx/Parse.hs+11−14
@@ -132,21 +132,23 @@ mapD f xs =
132132 in
133133 concatMapM handler xs
134134
135−unwrapSDT :: NameSpaces -> Content -> [Content]
136−unwrapSDT ns (Elem element)
135+unwrap :: NameSpaces -> Content -> [Content]
136+unwrap ns (Elem element)
137137 | isElem ns "w" "sdt" element
138138 , Just sdtContent <- findChildByName ns "w" "sdtContent" element
139− = concatMap (unwrapSDT ns) $ map Elem $ elChildren sdtContent
140−unwrapSDT _ content = [content]
139+ = concatMap (unwrap ns) $ map Elem $ elChildren sdtContent
140+ | isElem ns "w" "smartTag" element
141+ = concatMap (unwrap ns) $ map Elem $ elChildren element
142+unwrap _ content = [content]
141143
142−unwrapSDTchild :: NameSpaces -> Content -> Content
143−unwrapSDTchild ns (Elem element) =
144− Elem $ element { elContent = concatMap (unwrapSDT ns) (elContent element) }
145−unwrapSDTchild _ content = content
144+unwrapChild :: NameSpaces -> Content -> Content
145+unwrapChild ns (Elem element) =
146+ Elem $ element { elContent = concatMap (unwrap ns) (elContent element) }
147+unwrapChild _ content = content
146148
147149walkDocument' :: NameSpaces -> XMLC.Cursor -> XMLC.Cursor
148150walkDocument' ns cur =
149− let modifiedCur = XMLC.modifyContent (unwrapSDTchild ns) cur
151+ let modifiedCur = XMLC.modifyContent (unwrapChild ns) cur
150152 in
151153 case XMLC.nextDF modifiedCur of
152154 Just cur' -> walkDocument' ns cur'
@@ -275,7 +277,6 @@ data ParPart = PlainRun Run
275277 | Drawing FilePath String String B.ByteString Extent -- title, alt
276278 | Chart -- placeholder for now
277279 | PlainOMath [Exp]
278− | SmartTag [Run]
279280 | Field FieldInfo [Run]
280281 | NullParPart -- when we need to return nothing, but
281282 -- not because of an error.
@@ -825,10 +826,6 @@ elemToParPart ns element
825826 | Just change <- getTrackedChange ns element = do
826827 runs <- mapD (elemToRun ns) (elChildren element)
827828 return $ ChangedRuns change runs
828−elemToParPart ns element
829− | isElem ns "w" "smartTag" element = do
830− runs <- mapD (elemToRun ns) (elChildren element)
831− return $ SmartTag runs
832829elemToParPart ns element
833830 | isElem ns "w" "bookmarkStart" element
834831 , Just bmId <- findAttrByName ns "w" "id" element