aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-09-30 16:04:05 -0700
committerJohn MacFarlane <[email protected]>2024-09-30 16:05:57 -0700
commit752d57dac18b2381fb05972cccdc21ea16d242cd (patch)
tree4a32900e387bc9530da10803958a543f82d7d0e9
parentb4df43b01f87525a054a54e5799fb7d0c57f6b7e (diff)
RST writer: handle cases where indented context starts with block quote.
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.
-rw-r--r--src/Text/Pandoc/Writers/RST.hs28
-rw-r--r--test/command/10236.md38
2 files changed, 62 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 237a467b7..4f14030db 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -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)
@@ -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
@@ -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
@@ -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
diff --git a/test/command/10236.md b/test/command/10236.md
new file mode 100644
index 000000000..9406e7a04
--- /dev/null
+++ b/test/command/10236.md
@@ -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
+```