git.iko.soy/typeable/pandoc
on master help sign in
RST reader/writer: support unknown interpreted text roles...
d1444b4John MacFarlane
src/Text/Pandoc/Readers/RST.hs+2−4
@@ -1399,10 +1399,8 @@ renderRole contents fmt role attr = case role of
1399 case M.lookup custom customRoles of
1399 case M.lookup custom customRoles of
1400 Just (newRole, newFmt, newAttr) ->
1400 Just (newRole, newFmt, newAttr) ->
1401 renderRole contents newFmt newRole newAttr
1401 renderRole contents newFmt newRole newAttr
1402− Nothing -> do
1402+ Nothing -> -- undefined role
1403− pos <- getPosition
1404− logMessage $ SkippedContent (":" ++ custom ++ ":") pos
1405− return $ B.str contents -- Undefined role
1403+ return $ B.spanWith ("",[],[("role",role)]) (B.str contents)
1406 where
1404 where
1407 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
1405 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
1408 rfcLink rfcNo = B.link rfcUrl ("RFC " ++ rfcNo) $ B.str ("RFC " ++ rfcNo)
1406 rfcLink rfcNo = B.link rfcUrl ("RFC " ++ rfcNo) $ B.str ("RFC " ++ rfcNo)
src/Text/Pandoc/Writers/RST.hs+6−1
@@ -439,7 +439,12 @@ inlineListToRST lst =
439
439
440-- | Convert Pandoc inline element to RST.
440-- | Convert Pandoc inline element to RST.
441inlineToRST :: PandocMonad m => Inline -> RST m Doc
441inlineToRST :: PandocMonad m => Inline -> RST m Doc
442−inlineToRST (Span _ ils) = inlineListToRST ils
442+inlineToRST (Span (_,_,kvs) ils) = do
443+ contents <- inlineListToRST ils
444+ return $
445+ case lookup "role" kvs of
446+ Just role -> ":" <> text role <> ":`" <> contents <> "`"
447+ Nothing -> contents
443inlineToRST (Emph lst) = do
448inlineToRST (Emph lst) = do
444 contents <- inlineListToRST lst
449 contents <- inlineListToRST lst
445 return $ "*" <> contents <> "*"
450 return $ "*" <> contents <> "*"
test/Tests/Readers/RST.hs+2−1
@@ -162,7 +162,8 @@ tests = [ "line block with blank line" =:
162 , "role with recursive inheritance"
162 , "role with recursive inheritance"
163 =: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
163 =: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
164 =?> para (codeWith ("", ["lhs", "haskell", "sourceCode"], []) "text")
164 =?> para (codeWith ("", ["lhs", "haskell", "sourceCode"], []) "text")
165− , "unknown role" =: ":unknown:`text`" =?> para (str "text")
165+ , "unknown role" =: ":unknown:`text`" =?>
166+ para (spanWith ("",[],[("role","unknown")]) (str "text"))
166 ]
167 ]
167 , testGroup "footnotes"
168 , testGroup "footnotes"
168 [ "remove space before note" =: T.unlines
169 [ "remove space before note" =: T.unlines
test/command/3407.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f native -t rst
3+[Para [Span ("",[],[("role","foo")]) [Str "text"]]]
4+^D
5+:foo:`text`
6+```
7+
8+```
9+% pandoc -f rst -t native
10+:foo:`text`
11+^D
12+[Para [Span ("",[],[("role","foo")]) [Str "text"]]]
13+```