aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-05-06 22:13:59 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-05-06 22:14:35 -0700
commit10644607e35369ec3b19b5d02fbe9b936d0ecb85 (patch)
tree7449b5751d7e9f27db547c8a45a5c178a974f999 /src/Text/Pandoc
parente7b42947bfa3d59ac59bf2b8d1e17415c24f518f (diff)
downloadpandoc-10644607e35369ec3b19b5d02fbe9b936d0ecb85.tar.gz
Textile reader: Rewrote some inline parsing code for clarity.
(It seems clearer to put the whitespace parsing in the grouped parser. This also uses stateLastStrPos to determine when the border is adjacent to an alphanumeric.)
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index ae9c0cc8e..3c07a4d85 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -596,32 +596,28 @@ ungroupedSimpleInline :: Parser [Char] ParserState t -- ^ surrounding
ungroupedSimpleInline border construct = try $ do
st <- getState
pos <- getPosition
- isWhitespace <- option False (whitespace >> return True)
- guard $ (stateQuoteContext st /= NoQuote)
- || (sourceColumn pos == 1)
- || isWhitespace
+ let afterString = stateLastStrPos st == Just pos
+ guard $ not afterString
border *> notFollowedBy (oneOf " \t\n\r")
attr <- attributes
body <- trimInlines . mconcat <$>
withQuoteContext InSingleQuote
(manyTill inline (try border <* notFollowedBy alphaNum))
- let result = construct $
+ return $ construct $
if attr == nullAttr
then body
else B.spanWith attr body
- return $ if isWhitespace
- then B.space <> result
- else result
groupedSimpleInline :: Parser [Char] ParserState t
-> (Inlines -> Inlines)
-> Parser [Char] ParserState Inlines
groupedSimpleInline border construct = try $ do
char '['
- withQuoteContext InSingleQuote (simpleInline border construct) >>~ char ']'
-
-
-
+ sp1 <- option mempty $ B.space <$ whitespace
+ result <- withQuoteContext InSingleQuote (simpleInline border construct)
+ sp2 <- option mempty $ B.space <$ whitespace
+ char ']'
+ return $ sp1 <> result <> sp2
-- | Create a singleton list
singleton :: a -> [a]