aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-06 22:11:27 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-06 22:12:18 -0800
commitc66921f2acea456af527b93e2daa1d8594798642 (patch)
tree962297050e4637853b0e2d7c87af839493f0f87e /src/Text
parent7864f30717767f89ee33532b59819b51ef2e14d4 (diff)
downloadpandoc-c66921f2acea456af527b93e2daa1d8594798642.tar.gz
Markdown reader: better handling of intraword _.
The 'str' parser now reads internal _'s as part of the string. This prevents pandoc from getting started looking for an emphasized block, which can cause exponential slowdowns in some cases. Resolves Issue #182.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 90e8e19bb..ad7d2a0cc 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -47,7 +47,7 @@ import Text.Pandoc.Readers.HTML ( rawHtmlBlock, anyHtmlBlockTag,
htmlBlockElement, htmlComment, unsanitaryURI )
import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
import Text.ParserCombinators.Parsec
-import Control.Monad (when, liftM, unless, guard)
+import Control.Monad (when, liftM, guard)
import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
-- | Read markdown from an input string and return a Pandoc document.
@@ -121,7 +121,7 @@ inlinesInBalancedBrackets :: GenParser Char ParserState Inline
inlinesInBalancedBrackets parser = try $ do
char '['
result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
- unless (res == "[") pzero
+ guard (res == "[")
bal <- inlinesInBalancedBrackets parser
return $ [Str "["] ++ bal ++ [Str "]"])
<|> (count 1 parser))
@@ -1138,7 +1138,9 @@ strChar = noneOf (specialChars ++ " \t\n")
str :: GenParser Char ParserState Inline
str = do
- result <- many1 strChar
+ a <- strChar
+ as <- many (strChar <|> (try $ char '_' >>~ lookAhead strChar))
+ let result = a:as
state <- getState
let spacesToNbr = map (\c -> if c == ' ' then '\160' else c)
if stateSmart state