aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-09-30 20:28:50 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-09-30 20:28:50 -0700
commite8260c27e18577b9af3d293b7cb9565b6dc9af6b (patch)
tree6c8d555f30fcae6d0469d3bffab412a48ab5efb3 /src
parent9366d8681d39ff892ab477fba637b65d62a0c776 (diff)
downloadpandoc-e8260c27e18577b9af3d293b7cb9565b6dc9af6b.tar.gz
RST reader: Consolidate super/subscript, math into interpretedRole.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs61
1 files changed, 26 insertions, 35 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 4ab60c77e..f30eb6ef3 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -854,9 +854,6 @@ inline = choice [ whitespace
, emph
, code
, subst
- , superscript
- , subscript
- , math
, interpretedRole
, note
, smart
@@ -907,42 +904,36 @@ strong :: RSTParser Inlines
strong = B.strong . trimInlines . mconcat <$>
enclosed (atStart $ string "**") (try $ string "**") inline
--- 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] -> RSTParser [Char]
-interpreted role = try $ do
- state <- getState
- if role == stateRstDefaultRole state
- then try markedInterpretedText <|> unmarkedInterpretedText
- else markedInterpretedText
- where
- markedInterpretedText = try (roleMarker *> unmarkedInterpretedText)
- <|> (unmarkedInterpretedText <* roleMarker)
- 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
+-- 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
+interpretedRole :: RSTParser Inlines
+interpretedRole = try $ do
+ (role, contents) <- roleBefore <|> roleAfter
+ case role of
+ "sup" -> return $ B.superscript $ B.str contents
+ "sub" -> return $ B.subscript $ B.str contents
+ "math" -> return $ B.math contents
+ _ -> return $ B.str contents --unknown
+
+roleMarker :: RSTParser String
+roleMarker = char ':' *> many1Till (letter <|> char '-') (char ':')
+
+roleBefore :: RSTParser (String,String)
+roleBefore = try $ do
+ role <- roleMarker
+ contents <- unmarkedInterpretedText
+ return (role,contents)
+
+roleAfter :: RSTParser (String,String)
+roleAfter = try $ do
+ contents <- unmarkedInterpretedText
+ role <- roleMarker <|> (stateRstDefaultRole <$> getState)
+ return (role,contents)
unmarkedInterpretedText :: RSTParser [Char]
unmarkedInterpretedText = enclosed (atStart $ char '`') (char '`') anyChar
--- For unknown interpreted roles, we just ignore the role.
-interpretedRole :: RSTParser Inlines
-interpretedRole = try $ B.str <$>
- ( (roleMarker *> unmarkedInterpretedText)
- <|> (unmarkedInterpretedText <* roleMarker) )
- where roleMarker = char ':' *> many1Till (letter <|> char '-') (char ':')
-
-superscript :: RSTParser Inlines
-superscript = B.superscript . B.str <$> interpreted "sup"
-
-subscript :: RSTParser Inlines
-subscript = B.subscript . B.str <$> interpreted "sub"
-
-math :: RSTParser Inlines
-math = B.math <$> interpreted "math"
-
whitespace :: RSTParser Inlines
whitespace = B.space <$ skipMany1 spaceChar <?> "whitespace"