diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2018-01-16 12:50:37 -0500 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2018-01-16 13:22:02 -0500 |
commit | ae8c0cdba82c9cfb847025c3f5ca410407b0fb96 (patch) | |
tree | 9eb95b83ccbcc97a4273e107f92d2b7abdc6de3b /src/Text/Pandoc/Readers/Docx/Parse.hs | |
parent | 404706d29a8f45b43ef2ef13e93d1786dde863a0 (diff) |
Docx reader: Parse instrText info in fldChar tags.
We introduce a new module, Text.Pandoc.Readers.Docx.Fields which
contains a simple parsec parser. At the moment, only simple hyperlink
fields are accepted, but that can be extended in the future.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx/Parse.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx/Parse.hs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index b3a0fee8e..5f648666f 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -54,6 +54,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..) , TrackedChange(..) , ChangeType(..) , ChangeInfo(..) + , FieldInfo(..) , archiveToDocx , archiveToDocxWithWarnings ) where @@ -70,6 +71,7 @@ import qualified Data.Map as M import Data.Maybe import System.FilePath import Text.Pandoc.Readers.Docx.Util +import Text.Pandoc.Readers.Docx.Fields import Text.Pandoc.Shared (filteredFilesFromArchive, safeRead) import qualified Text.Pandoc.UTF8 as UTF8 import Text.TeXMath (Exp) @@ -286,10 +288,6 @@ data Run = Run RunStyle [RunElem] | InlineChart -- placeholder deriving Show -data FieldInfo = HyperlinkField URL - | UnknownField - deriving (Show) - data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen deriving Show @@ -802,9 +800,19 @@ elemToParPart ns element return NullParPart FldCharContent info runs | fldCharType == "end" -> do modify $ \st -> st {stateFldCharState = FldCharClosed} - return $ Field info runs + return $ Field info $ reverse runs _ -> throwError WrongElem elemToParPart ns element + | isElem ns "w" "r" element + , Just instrText <- findChildByName ns "w" "instrText" element = do + fldCharState <- gets stateFldCharState + case fldCharState of + FldCharOpen -> do + info <- eitherToD $ parseFieldInfo $ strContent instrText + modify $ \st -> st{stateFldCharState = FldCharFieldInfo info} + return NullParPart + _ -> return NullParPart +elemToParPart ns element | isElem ns "w" "r" element = do run <- elemToRun ns element -- we check to see if we have an open FldChar in state that we're |