summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx/Util.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-03 22:23:07 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-03 22:23:07 +0100
commit76aa43c579cf9662143d2f145cc44f3a094d139a (patch)
tree9e2ea482d30a10b86acb62a3dfea609bb3964d5c /src/Text/Pandoc/Readers/Docx/Util.hs
parented4f84e84b1f7e498850e7948e625c7832286f74 (diff)
Docx reader: handle local namespace declarations.
Previously we didn't recognize math, for example, when the xmlns declaration occured on the element and not the root. Now we recognize either. Closes #3365. This patch defines findChildByName, findChildrenByName, and findAttrByName in Util, and uses these in Parse.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx/Util.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Util.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Util.hs b/src/Text/Pandoc/Readers/Docx/Util.hs
index 33d69ccf3..6646e5b7f 100644
--- a/src/Text/Pandoc/Readers/Docx/Util.hs
+++ b/src/Text/Pandoc/Readers/Docx/Util.hs
@@ -3,6 +3,9 @@ module Text.Pandoc.Readers.Docx.Util (
, elemName
, isElem
, elemToNameSpaces
+ , findChildByName
+ , findChildrenByName
+ , findAttrByName
) where
import Text.XML.Light
@@ -23,5 +26,22 @@ elemName ns prefix name =
isElem :: NameSpaces -> String -> String -> Element -> Bool
isElem ns prefix name element =
- qName (elName element) == name &&
- qURI (elName element) == lookup prefix ns
+ let ns' = ns ++ elemToNameSpaces element
+ in qName (elName element) == name &&
+ qURI (elName element) == lookup prefix ns'
+
+findChildByName :: NameSpaces -> String -> String -> Element -> Maybe Element
+findChildByName ns pref name el =
+ let ns' = ns ++ elemToNameSpaces el
+ in findChild (elemName ns' pref name) el
+
+findChildrenByName :: NameSpaces -> String -> String -> Element -> [Element]
+findChildrenByName ns pref name el =
+ let ns' = ns ++ elemToNameSpaces el
+ in findChildren (elemName ns' pref name) el
+
+findAttrByName :: NameSpaces -> String -> String -> Element -> Maybe String
+findAttrByName ns pref name el =
+ let ns' = ns ++ elemToNameSpaces el
+ in findAttr (elemName ns' pref name) el
+