aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2018-03-13 14:22:50 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2018-03-13 22:15:11 -0400
commitb3fe95d7219c27233792361e4e423123cdf6a256 (patch)
treefeb6783def6f315cf7b29ae9033e85443d495203 /src/Text
parent17725a0661dabd8d8b9203adbe08fe9e4c6780fe (diff)
downloadpandoc-b3fe95d7219c27233792361e4e423123cdf6a256.tar.gz
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
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs2
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs25
2 files changed, 11 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 582b4be13..104e17c18 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -460,8 +460,6 @@ parPartToInlines' (ExternalHyperLink target runs) = do
return $ link target "" ils
parPartToInlines' (PlainOMath exps) =
return $ math $ writeTeX exps
-parPartToInlines' (SmartTag runs) =
- smushInlines <$> mapM runToInlines runs
parPartToInlines' (Field info runs) =
case info of
HyperlinkField url -> parPartToInlines' $ ExternalHyperLink url runs
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 1f7f07e36..dcf2e0493 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -132,21 +132,23 @@ mapD f xs =
in
concatMapM handler xs
-unwrapSDT :: NameSpaces -> Content -> [Content]
-unwrapSDT ns (Elem element)
+unwrap :: NameSpaces -> Content -> [Content]
+unwrap ns (Elem element)
| isElem ns "w" "sdt" element
, Just sdtContent <- findChildByName ns "w" "sdtContent" element
- = concatMap (unwrapSDT ns) $ map Elem $ elChildren sdtContent
-unwrapSDT _ content = [content]
+ = concatMap (unwrap ns) $ map Elem $ elChildren sdtContent
+ | isElem ns "w" "smartTag" element
+ = concatMap (unwrap ns) $ map Elem $ elChildren element
+unwrap _ content = [content]
-unwrapSDTchild :: NameSpaces -> Content -> Content
-unwrapSDTchild ns (Elem element) =
- Elem $ element { elContent = concatMap (unwrapSDT ns) (elContent element) }
-unwrapSDTchild _ content = content
+unwrapChild :: NameSpaces -> Content -> Content
+unwrapChild ns (Elem element) =
+ Elem $ element { elContent = concatMap (unwrap ns) (elContent element) }
+unwrapChild _ content = content
walkDocument' :: NameSpaces -> XMLC.Cursor -> XMLC.Cursor
walkDocument' ns cur =
- let modifiedCur = XMLC.modifyContent (unwrapSDTchild ns) cur
+ let modifiedCur = XMLC.modifyContent (unwrapChild ns) cur
in
case XMLC.nextDF modifiedCur of
Just cur' -> walkDocument' ns cur'
@@ -275,7 +277,6 @@ data ParPart = PlainRun Run
| Drawing FilePath String String B.ByteString Extent -- title, alt
| Chart -- placeholder for now
| PlainOMath [Exp]
- | SmartTag [Run]
| Field FieldInfo [Run]
| NullParPart -- when we need to return nothing, but
-- not because of an error.
@@ -826,10 +827,6 @@ elemToParPart ns element
runs <- mapD (elemToRun ns) (elChildren element)
return $ ChangedRuns change runs
elemToParPart ns element
- | isElem ns "w" "smartTag" element = do
- runs <- mapD (elemToRun ns) (elChildren element)
- return $ SmartTag runs
-elemToParPart ns element
| isElem ns "w" "bookmarkStart" element
, Just bmId <- findAttrByName ns "w" "id" element
, Just bmName <- findAttrByName ns "w" "name" element =