git.iko.soy/typeable/pandoc
on master help sign in
Don't recognize inline-markup starts inside words.
26748daJohn MacFarlane
src/Text/Pandoc/Readers/RST.hs+17−8
@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Pandoc.Parsing
35import Text.Pandoc.Parsing
36import Text.ParserCombinators.Parsec
36import Text.ParserCombinators.Parsec
37−import Control.Monad ( when, liftM )
37+import Control.Monad ( when, liftM, guard )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
39import qualified Data.Map as M
39import qualified Data.Map as M
40import Text.Printf ( printf )
40import Text.Printf ( printf )
@@ -58,7 +58,7 @@ underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
58
58
59-- treat these as potentially non-text when parsing inline:
59-- treat these as potentially non-text when parsing inline:
60specialChars :: [Char]
60specialChars :: [Char]
61−specialChars = "\\`|*_<>$:[]()-.\"'\8216\8217\8220\8221"
61+specialChars = "\\`|*_<>$:/[]{}()-.\"'\8216\8217\8220\8221"
62
62
63--
63--
64-- parsing documents
64-- parsing documents
@@ -831,12 +831,21 @@ code = try $ do
831 return $ Code nullAttr
831 return $ Code nullAttr
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
833
833
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+
834emph :: GenParser Char ParserState Inline
843emph :: GenParser Char ParserState Inline
835−emph = enclosed (char '*') (char '*') inline >>=
844+emph = enclosed (atStart $ char '*') (char '*') inline >>=
836 return . Emph . normalizeSpaces
845 return . Emph . normalizeSpaces
837
846
838strong :: GenParser Char ParserState Inline
847strong :: GenParser Char ParserState Inline
839−strong = enclosed (string "**") (try $ string "**") inline >>=
848+strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
840 return . Strong . normalizeSpaces
849 return . Strong . normalizeSpaces
841
850
842-- Parses inline interpreted text which is required to have the given role.
851-- Parses inline interpreted text which is required to have the given role.
@@ -856,7 +865,7 @@ interpreted role = try $ do
856 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
865 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
857 -- but it should be good enough for most purposes
866 -- but it should be good enough for most purposes
858 unmarkedInterpretedText = do
867 unmarkedInterpretedText = do
859− result <- enclosed (char '`') (char '`') anyChar
868+ result <- enclosed (atStart $ char '`') (char '`') anyChar
860 return result
869 return result
861
870
862superscript :: GenParser Char ParserState Inline
871superscript :: GenParser Char ParserState Inline
@@ -873,9 +882,9 @@ whitespace = many1 spaceChar >> return Space <?> "whitespace"
873
882
874str :: GenParser Char ParserState Inline
883str :: GenParser Char ParserState Inline
875str = do
884str = do
876− result <- many1 (noneOf (specialChars ++ "\t\n "))
885+ let strChar = noneOf ("\t\n " ++ specialChars)
877− pos <- getPosition
886+ result <- many1 strChar
878− updateState $ \s -> s{ stateLastStrPos = Just pos }
887+ updateLastStrPos
879 return $ Str result
888 return $ Str result
880
889
881-- an endline character that can be treated as a space, not a structural break
890-- 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 ":
320,Para [Math DisplayMath "\\alpha = beta",Math DisplayMath "E = mc^2"]
320,Para [Math DisplayMath "\\alpha = beta",Math DisplayMath "E = mc^2"]
321,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 "."]
321,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 "."]
322,Para [Str "Reset",Space,Str "default",Str "-",Str "role",Space,Str "to",Space,Str "the",Space,Str "default",Space,Str "default",Str "."]
322,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.
593
593
594And now `some-invalid-string-3231231` is nonsense.
594And now `some-invalid-string-3231231` is nonsense.
595
595
596+Literal symbols
597+---------------
598+
599+2*2 = 4*1