RST writer: Fix missing spaces with nested inlines.
Previously spaces around links inside italics were omitted. Closes #8182.
This commit is contained in:
parent
c724e9cb7c
commit
98fb8521a7
3 changed files with 21 additions and 4 deletions
|
@ -32,7 +32,7 @@ import Text.Pandoc.Shared
|
|||
import Text.Pandoc.Templates (renderTemplate)
|
||||
import Text.Pandoc.Writers.Shared
|
||||
import Text.Pandoc.Walk
|
||||
import Safe (lastMay)
|
||||
import Safe (lastMay, headMay)
|
||||
|
||||
type Refs = [([Inline], Target)]
|
||||
|
||||
|
@ -478,7 +478,18 @@ transformInlines = insertBS .
|
|||
insertBS (x:ys) = x : insertBS ys
|
||||
insertBS [] = []
|
||||
transformNested :: [Inline] -> [Inline]
|
||||
transformNested = map (mapNested stripLeadingTrailingSpace)
|
||||
transformNested = concatMap exportLeadingTrailingSpace
|
||||
exportLeadingTrailingSpace :: Inline -> [Inline]
|
||||
exportLeadingTrailingSpace il
|
||||
| isComplex il =
|
||||
let contents = dropInlineParent il
|
||||
headSpace = headMay contents == Just Space
|
||||
lastSpace = lastMay contents == Just Space
|
||||
in (if headSpace then (Space:) else id) .
|
||||
(if lastSpace then (++ [Space]) else id) $
|
||||
[setInlineChildren il (stripLeadingTrailingSpace contents)]
|
||||
| otherwise = [il]
|
||||
|
||||
surroundComplex :: Inline -> Inline -> Bool
|
||||
surroundComplex (Str s) (Str s')
|
||||
| Just (_, c) <- T.unsnoc s
|
||||
|
|
|
@ -98,8 +98,8 @@ tests = [ testGroup "rubrics"
|
|||
strong (emph (link "loc" "" (str "text"))) =?>
|
||||
"`text <loc>`__"
|
||||
, "RST inlines cannot start nor end with spaces" =:
|
||||
emph (str "f" <> space <> strong (str "d") <> space <> str "l") =?>
|
||||
"*f*\\ **d**\\ *l*"
|
||||
emph (str "f" <> strong (space <> str "d" <> space) <> str "l") =?>
|
||||
"*f* **d** *l*"
|
||||
, "keeps quotes" =:
|
||||
strong (str "f" <> doubleQuoted (str "d") <> str "l") =?>
|
||||
"**f“d”l**"
|
||||
|
|
6
test/command/8182.md
Normal file
6
test/command/8182.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
```
|
||||
% pandoc -f dokuwiki -t rst
|
||||
This //text and [[https://pandoc.org/|link]] are in italic//.
|
||||
^D
|
||||
This *text and* `link <https://pandoc.org/>`__ *are in italic*.
|
||||
```
|
Loading…
Reference in a new issue