git.iko.soy/typeable/pandoc
on master help sign in
RST reader: remove support for nested inlines.

RST does not allow nested emphasis, links, or other inline constructs. Closes #4581, double parsing of links with URLs as link text. This supersedes the earlier fix for #4581 in 6419819b46c0d69c7024ba8aa4a6381cb311341c. Fixes #4561, a bug parsing with URLs inside emphasis. Closes #4792.

commitbe2d7921cbf33a3aa839cd54a0b3ec0a7dfc4a9b authordanse <f.occhipinti@gmail.com> dateMon 23 Apr 2018, 08:54 (8 years ago) parent50e8c3b
3 files changed+26−23
src/Text/Pandoc/Readers/RST.hs+15−17 test/Tests/Readers/RST.hs+11 test/command/4581.md−6
src/Text/Pandoc/Readers/RST.hs+15−17
@@ -45,7 +45,6 @@ import Data.Maybe (fromMaybe, isJust)
4545import Data.Sequence (ViewR (..), viewr)
4646import Data.Text (Text)
4747import qualified Data.Text as T
48−import Text.Pandoc.Walk (walk)
4948import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines)
5049import qualified Text.Pandoc.Builder as B
5150import Text.Pandoc.Class (PandocMonad, fetchItem, readFileFromDirs)
@@ -1314,19 +1313,24 @@ table = gridTable False <|> simpleTable False <|>
13141313
13151314inline :: PandocMonad m => RSTParser m Inlines
13161315inline = choice [ note -- can start with whitespace, so try before ws
1317− , whitespace
13181316 , link
1319− , str
13201317 , endline
13211318 , strong
13221319 , emph
13231320 , code
13241321 , subst
13251322 , interpretedRole
1326− , smart
1327− , hyphens
1328− , escapedChar
1329− , symbol ] <?> "inline"
1323+ , inlineContent ] <?> "inline"
1324+
1325+-- strings, spaces and other characters that can appear either by
1326+-- themselves or within inline markup
1327+inlineContent :: PandocMonad m => RSTParser m Inlines
1328+inlineContent = choice [ whitespace
1329+ , str
1330+ , smart
1331+ , hyphens
1332+ , escapedChar
1333+ , symbol ] <?> "inline content"
13301334
13311335parseInlineFromString :: PandocMonad m => String -> RSTParser m Inlines
13321336parseInlineFromString = parseFromString' (trimInlines . mconcat <$> many inline)
@@ -1369,11 +1373,11 @@ atStart p = do
13691373
13701374emph :: PandocMonad m => RSTParser m Inlines
13711375emph = B.emph . trimInlines . mconcat <$>
1372− enclosed (atStart $ char '*') (char '*') inline
1376+ enclosed (atStart $ char '*') (char '*') inlineContent
13731377
13741378strong :: PandocMonad m => RSTParser m Inlines
13751379strong = B.strong . trimInlines . mconcat <$>
1376− enclosed (atStart $ string "**") (try $ string "**") inline
1380+ enclosed (atStart $ string "**") (try $ string "**") inlineContent
13771381
13781382-- Note, this doesn't precisely implement the complex rule in
13791383-- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
@@ -1480,8 +1484,8 @@ explicitLink :: PandocMonad m => RSTParser m Inlines
14801484explicitLink = try $ do
14811485 char '`'
14821486 notFollowedBy (char '`') -- `` marks start of inline code
1483− label' <- removeLinks . trimInlines . mconcat <$>
1484− manyTill (notFollowedBy (char '`') >> inline) (char '<')
1487+ label' <- trimInlines . mconcat <$>
1488+ manyTill (notFollowedBy (char '`') >> inlineContent) (char '<')
14851489 src <- trim <$> manyTill (noneOf ">\n") (char '>')
14861490 skipSpaces
14871491 string "`_"
@@ -1495,12 +1499,6 @@ explicitLink = try $ do
14951499 _ -> return ((src, ""), nullAttr)
14961500 return $ B.linkWith attr (escapeURI src') tit label''
14971501
1498−removeLinks :: B.Inlines -> B.Inlines
1499−removeLinks = B.fromList . walk (concatMap go) . B.toList
1500− where go :: Inline -> [Inline]
1501− go (Link _ lab _) = lab
1502− go x = [x]
1503−
15041502citationName :: PandocMonad m => RSTParser m String
15051503citationName = do
15061504 raw <- citationMarker
test/Tests/Readers/RST.hs+11
@@ -188,4 +188,15 @@ tests = [ "line block with blank line" =:
188188 ] =?>
189189 para ("foo" <> note (para "bar"))
190190 ]
191+ , testGroup "inlines"
192+ [ "links can contain an URI without being parsed twice (#4581)" =:
193+ "`http://loc <http://loc>`__" =?>
194+ para (link "http://loc" "" "http://loc")
195+ , "inline markup cannot be nested" =:
196+ "**a*b*c**" =?>
197+ para (strong "a*b*c")
198+ , "bare URI parsing disabled inside emphasis (#4561)" =:
199+ "*http://location*" =?>
200+ para (emph (text "http://location"))
201+ ]
191202 ]
test/command/4581.mddeleted−6
@@ -1,6 +0,0 @@
1−```
2−% pandoc -f rst -t native
3−`http://loc <http://loc>`__
4−^D
5−[Para [Link ("",[],[]) [Str "http://loc"] ("http://loc","")]]
6−```