aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorGreg Maslov <gmaslov@bootis.org>2012-03-24 21:30:10 -0400
committerGreg Maslov <gmaslov@bootis.org>2012-03-24 21:48:54 -0400
commit618dc294f93f1865dcdfbfda21003745b4d6b389 (patch)
tree5054a79a2c3ea79dfa7d33d8cb078cf9f4964d51 /src/Text/Pandoc/Readers
parent3c4e1ff063100cbdf27f911fcbedbb842adf2af4 (diff)
downloadpandoc-618dc294f93f1865dcdfbfda21003745b4d6b389.tar.gz
Add parsing support for the rST default-role directive.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 30d9aae44..2fbf11cf7 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -129,6 +129,7 @@ block = choice [ codeBlock
, imageBlock
, customCodeBlock
, mathBlock
+ , defaultRoleBlock
, unknownDirective
, header
, hrule
@@ -533,6 +534,21 @@ bulletList = many1 (listItem bulletListStart) >>=
return . BulletList . compactify
--
+-- default-role block
+--
+
+defaultRoleBlock :: GenParser Char ParserState Block
+defaultRoleBlock = try $ do
+ string ".. default-role:: "
+ role <- manyTill anyChar newline >>= return . removeLeadingTrailingSpace
+ updateState $ \s -> s { stateRstDefaultRole =
+ if null role
+ then stateRstDefaultRole defaultParserState
+ else role
+ }
+ return Null
+
+--
-- unknown directive (e.g. comment)
--
@@ -805,13 +821,25 @@ strong :: GenParser Char ParserState Inline
strong = enclosed (string "**") (try $ string "**") inline >>=
return . Strong . normalizeSpaces
-interpreted :: [Char] -> GenParser Char st [Char]
+-- Parses inline interpreted text which is required to have the given role.
+-- This decision is based on the role marker (if present),
+-- and the current default interpreted text role.
+interpreted :: [Char] -> GenParser Char ParserState [Char]
interpreted role = try $ do
+ state <- getState
+ if role == stateRstDefaultRole state
+ then try markedInterpretedText <|> unmarkedInterpretedText
+ else markedInterpretedText
+ where
+ markedInterpretedText = try (roleMarker >> unmarkedInterpretedText)
+ <|> (unmarkedInterpretedText >>= (\txt -> roleMarker >> return txt))
+ roleMarker = string $ ":" ++ role ++ ":"
-- Note, this doesn't precisely implement the complex rule in
-- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
-- but it should be good enough for most purposes
- result <- enclosed (string $ ":" ++ role ++ ":`") (char '`') anyChar
- return result
+ unmarkedInterpretedText = do
+ result <- enclosed (char '`') (char '`') anyChar
+ return result
superscript :: GenParser Char ParserState Inline
superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])