git.iko.soy/typeable/pandoc
on master help sign in
RST reader/writer: support unknown interpreted text roles...

...by parsing them as Span with "role" attributes. This way they can be manipulated in the AST. Closes #3407.

commitd1444b4ecdd7bc2f3b6180ceb2635d51382c4ab8 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 17 Aug 2017, 16:01 (9 years ago) parentb1f6fb4
4 files changed+23−6
src/Text/Pandoc/Readers/RST.hs+2−4 src/Text/Pandoc/Writers/RST.hs+6−1 test/Tests/Readers/RST.hs+2−1 test/command/3407.md+13
src/Text/Pandoc/Readers/RST.hs+2−4
@@ -1399,10 +1399,8 @@ renderRole contents fmt role attr = case role of
13991399 case M.lookup custom customRoles of
14001400 Just (newRole, newFmt, newAttr) ->
14011401 renderRole contents newFmt newRole newAttr
1402− Nothing -> do
1403− pos <- getPosition
1404− logMessage $ SkippedContent (":" ++ custom ++ ":") pos
1405− return $ B.str contents -- Undefined role
1402+ Nothing -> -- undefined role
1403+ return $ B.spanWith ("",[],[("role",role)]) (B.str contents)
14061404 where
14071405 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
14081406 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 =
439439
440440-- | Convert Pandoc inline element to RST.
441441inlineToRST :: 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
443448inlineToRST (Emph lst) = do
444449 contents <- inlineListToRST lst
445450 return $ "*" <> contents <> "*"
test/Tests/Readers/RST.hs+2−1
@@ -162,7 +162,8 @@ tests = [ "line block with blank line" =:
162162 , "role with recursive inheritance"
163163 =: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
164164 =?> 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"))
166167 ]
167168 , testGroup "footnotes"
168169 [ "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+```