Skip to content

Commit

Permalink
RST writer: handle cases where indented context starts with block quote.
Browse files Browse the repository at this point in the history
In these cases we emit an empty comment to fix the point from
which indentation is measured; otherwise the block quote is not
parsed as a block quote.

This affects list items and admonitions.

Cloess #10236.
  • Loading branch information
jgm committed Sep 30, 2024
1 parent b4df43b commit 752d57d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Text/Pandoc/Writers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,17 @@ blockToRST (Div (ident,classes,_kvs) bs) = do
-> ".. " <> literal cl <> "::"
cls -> ".. container::" <> space <>
literal (T.unwords (filter (/= "container") cls))
-- if contents start with block quote, we need to insert
-- an empty comment to fix the indentation point (#10236)
let contents' = case bs of
BlockQuote{}:_-> ".." $+$ contents
_ -> contents
return $ blankline $$
admonition $$
(if T.null ident
then blankline
else " :name: " <> literal ident $$ blankline) $$
nest 3 contents $$
nest 3 contents' $$
blankline
blockToRST (Plain inlines) = inlineListToRST inlines
blockToRST (Para inlines)
Expand Down Expand Up @@ -421,7 +426,12 @@ blockToRST (Figure (ident, classes, _kvs)
bulletListItemToRST :: PandocMonad m => [Block] -> RST m (Doc Text)
bulletListItemToRST items = do
contents <- blockListToRST items
return $ hang 3 "- " contents $$
-- if a list item starts with block quote, we need to insert
-- an empty comment to fix the indentation point (#10236)
let contents' = case items of
BlockQuote{}:_-> ".." $+$ contents
_ -> contents
return $ hang 3 "- " contents' $$
if null items || (endsWithPlain items && not (endsWithList items))
then cr
else blankline
Expand All @@ -434,7 +444,12 @@ orderedListItemToRST :: PandocMonad m
orderedListItemToRST marker items = do
contents <- blockListToRST items
let marker' = marker <> " "
return $ hang (T.length marker') (literal marker') contents $$
-- if a list item starts with block quote, we need to insert
-- an empty comment to fix the indentation point (#10236)
let contents' = case items of
BlockQuote{}:_-> ".." $+$ contents
_ -> contents
return $ hang (T.length marker') (literal marker') contents' $$
if null items || (endsWithPlain items && not (endsWithList items))
then cr
else blankline
Expand All @@ -450,7 +465,12 @@ definitionListItemToRST :: PandocMonad m => ([Inline], [[Block]]) -> RST m (Doc
definitionListItemToRST (label, defs) = do
label' <- inlineListToRST label
contents <- liftM vcat $ mapM blockListToRST defs
return $ nowrap label' $$ nest 3 (nestle contents) $$
-- if definition list starts with block quote, we need to insert
-- an empty comment to fix the indentation point (#10236)
let contents' = case defs of
(BlockQuote{}:_):_ -> ".." $+$ contents
_ -> contents
return $ nowrap label' $$ nest 3 (nestle contents') $$
if isTightList defs
then cr
else blankline
Expand Down
38 changes: 38 additions & 0 deletions test/command/10236.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
```
% pandoc -t rst
- > test
>
> para 2
^D
- ..
test
para 2
```

```
% pandoc -t rst
1. > test
>
> para 2
^D
1. ..
test
para 2
```

```
% pandoc -t rst
::: caution
> test
:::
^D
.. caution::
..
test
```

0 comments on commit 752d57d

Please sign in to comment.