aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx/Fields.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx/Fields.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Fields.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Fields.hs b/src/Text/Pandoc/Readers/Docx/Fields.hs
index 442bc3466..5f090b6be 100644
--- a/src/Text/Pandoc/Readers/Docx/Fields.hs
+++ b/src/Text/Pandoc/Readers/Docx/Fields.hs
@@ -21,8 +21,11 @@ import Text.Parsec
import Text.Parsec.Text (Parser)
type URL = T.Text
+type Anchor = T.Text
data FieldInfo = HyperlinkField URL
+ -- The boolean indicates whether the field is a hyperlink.
+ | PagerefField Anchor Bool
| UnknownField
deriving (Show)
@@ -33,6 +36,8 @@ fieldInfo :: Parser FieldInfo
fieldInfo =
try (HyperlinkField <$> hyperlink)
<|>
+ try ((uncurry PagerefField) <$> pageref)
+ <|>
return UnknownField
escapedQuote :: Parser T.Text
@@ -72,3 +77,23 @@ hyperlink = do
("\\l", s) : _ -> farg <> "#" <> s
_ -> farg
return url
+
+-- See ยง17.16.5.45
+pagerefSwitch :: Parser (T.Text, T.Text)
+pagerefSwitch = do
+ sw <- string "\\h"
+ spaces
+ farg <- fieldArgument
+ return (T.pack sw, farg)
+
+pageref :: Parser (Anchor, Bool)
+pageref = do
+ many space
+ string "PAGEREF"
+ spaces
+ farg <- fieldArgument
+ switches <- spaces *> many pagerefSwitch
+ let isLink = case switches of
+ ("\\h", _) : _ -> True
+ _ -> False
+ return (farg, isLink)