aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-05-06 23:27:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-05-06 23:27:16 -0700
commit442eecc15c2b805872600e111a510e022d1920f7 (patch)
tree51818e58c8c565412080b18fb664cb2e77ceadc2 /src/Text/Pandoc/Readers
parentea4e947bd0308861dbbbe020d21afe7943db1b98 (diff)
downloadpandoc-442eecc15c2b805872600e111a510e022d1920f7.tar.gz
Textile reader: Rewrote simpleInline for clarity and efficiency.
This way we only look once for the opening `[`.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index 622a41168..f83298d4c 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -381,6 +381,7 @@ inline = do
-- | Inline parsers tried in order
inlineParsers :: [Parser [Char] ParserState Inlines]
inlineParsers = [ inlineMarkup
+ , groupedInlineMarkup
, str
, whitespace
, endline
@@ -602,17 +603,10 @@ surrounded :: Parser [Char] st t -- ^ surrounding parser
surrounded border =
enclosed (border *> notFollowedBy (oneOf " \t\n\r")) (try border)
-
simpleInline :: Parser [Char] ParserState t -- ^ surrounding parser
- -> (Inlines -> Inlines) -- ^ Inline constructor
- -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly)
-simpleInline border construct = groupedSimpleInline border construct
- <|> ungroupedSimpleInline border construct
-
-ungroupedSimpleInline :: Parser [Char] ParserState t -- ^ surrounding parser
- -> (Inlines -> Inlines) -- ^ Inline constructor
- -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly)
-ungroupedSimpleInline border construct = try $ do
+ -> (Inlines -> Inlines) -- ^ Inline constructor
+ -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly)
+simpleInline border construct = try $ do
st <- getState
pos <- getPosition
let afterString = stateLastStrPos st == Just pos
@@ -627,13 +621,11 @@ ungroupedSimpleInline border construct = try $ do
then body
else B.spanWith attr body
-groupedSimpleInline :: Parser [Char] ParserState t
- -> (Inlines -> Inlines)
- -> Parser [Char] ParserState Inlines
-groupedSimpleInline border construct = try $ do
+groupedInlineMarkup :: Parser [Char] ParserState Inlines
+groupedInlineMarkup = try $ do
char '['
sp1 <- option mempty $ B.space <$ whitespace
- result <- withQuoteContext InSingleQuote (simpleInline border construct)
+ result <- withQuoteContext InSingleQuote inlineMarkup
sp2 <- option mempty $ B.space <$ whitespace
char ']'
return $ sp1 <> result <> sp2