summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx/Parse.hs
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-11-02 12:28:56 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2016-11-02 12:28:56 -0400
commit4a99e142ecbea4c9f16729468e45223ba200fcef (patch)
tree8d254e24de2111cc1ccf220f50835b7c23f5f267 /src/Text/Pandoc/Readers/Docx/Parse.hs
parent5684577da557b2fd3e44e648d1af94cb1367610f (diff)
Docx Reader: abstract out function to avoid code repetition.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx/Parse.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index a821d0693..94e3e29cf 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -645,18 +645,23 @@ expandDrawingId s = do
Nothing -> throwError DocxError
Nothing -> throwError DocxError
+getTitleAndAlt :: NameSpaces -> Element -> (String, String)
+getTitleAndAlt ns element =
+ let mbDocPr = findChild (elemName ns "wp" "inline") element >>=
+ findChild (elemName ns "wp" "docPr")
+ title = case mbDocPr >>= findAttr (elemName ns "" "title") of
+ Just title' -> title'
+ Nothing -> ""
+ alt = case mbDocPr >>= findAttr (elemName ns "" "descr") of
+ Just alt' -> alt'
+ Nothing -> ""
+ in (title, alt)
+
elemToParPart :: NameSpaces -> Element -> D ParPart
elemToParPart ns element
| isElem ns "w" "r" element
, Just drawingElem <- findChild (elemName ns "w" "drawing") element =
- let mbDocPr = findChild (elemName ns "wp" "inline") drawingElem >>=
- findChild (elemName ns "wp" "docPr")
- alt = case mbDocPr >>= findAttr (elemName ns "" "descr") of
- Just alt' -> alt'
- Nothing -> ""
- title = case mbDocPr >>= findAttr (elemName ns "" "title") of
- Just title' -> title'
- Nothing -> ""
+ let (title, alt) = getTitleAndAlt ns drawingElem
a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
>>= findAttr (elemName ns "r" "embed")
@@ -760,14 +765,7 @@ elemToExtent drawingElem =
childElemToRun :: NameSpaces -> Element -> D Run
childElemToRun ns element
| isElem ns "w" "drawing" element =
- let mbDocPr = findChild (elemName ns "wp" "inline") element >>=
- findChild (elemName ns "wp" "docPr")
- alt = case mbDocPr >>= findAttr (elemName ns "" "descr") of
- Just alt' -> alt'
- Nothing -> ""
- title = case mbDocPr >>= findAttr (elemName ns "" "title") of
- Just title' -> title'
- Nothing -> ""
+ let (title, alt) = getTitleAndAlt ns element
a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
>>= findAttr (QName "embed" (lookup "r" ns) (Just "r"))