From 10644607e35369ec3b19b5d02fbe9b936d0ecb85 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 6 May 2014 22:13:59 -0700 Subject: 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.) --- src/Text/Pandoc/Readers/Textile.hs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/Text/Pandoc/Readers') 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] -- cgit v1.2.3