git.iko.soy/typeable/pandoc
on master help sign in
Don't recognize inline-markup starts inside words.

For example, "2*2 = 4*1" should not contain an emphasized section. Added test case for "Literal symbols". Closes #569.

commit26748da6d4fc6912f1ef314fb01f9969d8a5fc59 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 16 Jul 2012, 10:14 (14 years ago) parentf68b05e
3 files changed+24−9
src/Text/Pandoc/Readers/RST.hs+17−8 tests/rst-reader.native+3−1 tests/rst-reader.rst+4
src/Text/Pandoc/Readers/RST.hs+17−8
@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.Pandoc.Parsing
3636import Text.ParserCombinators.Parsec
37−import Control.Monad ( when, liftM )
37+import Control.Monad ( when, liftM, guard )
3838import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
3939import qualified Data.Map as M
4040import Text.Printf ( printf )
@@ -58,7 +58,7 @@ underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
5858
5959-- treat these as potentially non-text when parsing inline:
6060specialChars :: [Char]
61−specialChars = "\\`|*_<>$:[]()-.\"'\8216\8217\8220\8221"
61+specialChars = "\\`|*_<>$:/[]{}()-.\"'\8216\8217\8220\8221"
6262
6363--
6464-- parsing documents
@@ -831,12 +831,21 @@ code = try $ do
831831 return $ Code nullAttr
832832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
833833
834+-- succeeds only if we're not right after a str (ie. in middle of word)
835+atStart :: GenParser Char ParserState a -> GenParser Char ParserState a
836+atStart p = do
837+ pos <- getPosition
838+ st <- getState
839+ -- single quote start can't be right after str
840+ guard $ stateLastStrPos st /= Just pos
841+ p
842+
834843emph :: GenParser Char ParserState Inline
835−emph = enclosed (char '*') (char '*') inline >>=
844+emph = enclosed (atStart $ char '*') (char '*') inline >>=
836845 return . Emph . normalizeSpaces
837846
838847strong :: GenParser Char ParserState Inline
839−strong = enclosed (string "**") (try $ string "**") inline >>=
848+strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
840849 return . Strong . normalizeSpaces
841850
842851-- Parses inline interpreted text which is required to have the given role.
@@ -856,7 +865,7 @@ interpreted role = try $ do
856865 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
857866 -- but it should be good enough for most purposes
858867 unmarkedInterpretedText = do
859− result <- enclosed (char '`') (char '`') anyChar
868+ result <- enclosed (atStart $ char '`') (char '`') anyChar
860869 return result
861870
862871superscript :: GenParser Char ParserState Inline
@@ -873,9 +882,9 @@ whitespace = many1 spaceChar >> return Space <?> "whitespace"
873882
874883str :: GenParser Char ParserState Inline
875884str = do
876− result <- many1 (noneOf (specialChars ++ "\t\n "))
877− pos <- getPosition
878− updateState $ \s -> s{ stateLastStrPos = Just pos }
885+ let strChar = noneOf ("\t\n " ++ specialChars)
886+ result <- many1 strChar
887+ updateLastStrPos
879888 return $ Str result
880889
881890-- an endline character that can be treated as a space, not a structural break
tests/rst-reader.native+3−1
@@ -320,4 +320,6 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":
320320,Para [Math DisplayMath "\\alpha = beta",Math DisplayMath "E = mc^2"]
321321,Para [Str "Some",Space,Superscript [Str "of"],Space,Str "these",Space,Superscript [Str "words"],Space,Str "are",Space,Str "in",Space,Superscript [Str "superscript"],Str "."]
322322,Para [Str "Reset",Space,Str "default",Str "-",Str "role",Space,Str "to",Space,Str "the",Space,Str "default",Space,Str "default",Str "."]
323−,Para [Str "And",Space,Str "now",Space,Str "`",Str "some",Str "-",Str "invalid",Str "-",Str "string",Str "-",Str "3231231",Str "`",Space,Str "is",Space,Str "nonsense",Str "."]]
323+,Para [Str "And",Space,Str "now",Space,Str "`",Str "some",Str "-",Str "invalid",Str "-",Str "string",Str "-",Str "3231231",Str "`",Space,Str "is",Space,Str "nonsense",Str "."]
324+,Header 2 [Str "Literal",Space,Str "symbols"]
325+,Para [Str "2",Str "*",Str "2",Space,Str "=",Space,Str "4",Str "*",Str "1"]]
tests/rst-reader.rst+4
@@ -593,3 +593,7 @@ Reset default-role to the default default.
593593
594594And now `some-invalid-string-3231231` is nonsense.
595595
596+Literal symbols
597+---------------
598+
599+2*2 = 4*1