Skip to content

Commit

Permalink
RST reader/writer: support unknown interpreted text roles...
Browse files Browse the repository at this point in the history
...by parsing them as Span with "role" attributes.
This way they can be manipulated in the AST.

Closes #3407.
  • Loading branch information
jgm committed Aug 17, 2017
1 parent b1f6fb4 commit d1444b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,10 +1399,8 @@ renderRole contents fmt role attr = case role of
case M.lookup custom customRoles of
Just (newRole, newFmt, newAttr) ->
renderRole contents newFmt newRole newAttr
Nothing -> do
pos <- getPosition
logMessage $ SkippedContent (":" ++ custom ++ ":") pos
return $ B.str contents -- Undefined role
Nothing -> -- undefined role
return $ B.spanWith ("",[],[("role",role)]) (B.str contents)
where
titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
rfcLink rfcNo = B.link rfcUrl ("RFC " ++ rfcNo) $ B.str ("RFC " ++ rfcNo)
Expand Down
7 changes: 6 additions & 1 deletion src/Text/Pandoc/Writers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,12 @@ inlineListToRST lst =

-- | Convert Pandoc inline element to RST.
inlineToRST :: PandocMonad m => Inline -> RST m Doc
inlineToRST (Span _ ils) = inlineListToRST ils
inlineToRST (Span (_,_,kvs) ils) = do
contents <- inlineListToRST ils
return $
case lookup "role" kvs of
Just role -> ":" <> text role <> ":`" <> contents <> "`"
Nothing -> contents
inlineToRST (Emph lst) = do
contents <- inlineListToRST lst
return $ "*" <> contents <> "*"
Expand Down
3 changes: 2 additions & 1 deletion test/Tests/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ tests = [ "line block with blank line" =:
, "role with recursive inheritance"
=: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
=?> para (codeWith ("", ["lhs", "haskell", "sourceCode"], []) "text")
, "unknown role" =: ":unknown:`text`" =?> para (str "text")
, "unknown role" =: ":unknown:`text`" =?>
para (spanWith ("",[],[("role","unknown")]) (str "text"))
]
, testGroup "footnotes"
[ "remove space before note" =: T.unlines
Expand Down
13 changes: 13 additions & 0 deletions test/command/3407.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```
% pandoc -f native -t rst
[Para [Span ("",[],[("role","foo")]) [Str "text"]]]
^D
:foo:`text`
```

```
% pandoc -f rst -t native
:foo:`text`
^D
[Para [Span ("",[],[("role","foo")]) [Str "text"]]]
```

0 comments on commit d1444b4

Please sign in to comment.