RST writer: use more consistent indentation.
Previously we used an odd mix of 3- and 4-space indentation. Now we use 3-space indentation, except for ordered lists, where indentation must depend on the width of the list marker. Closes #4563.
This commit is contained in:
parent
c76565bef5
commit
276894a2f2
7 changed files with 86 additions and 89 deletions
|
@ -263,7 +263,6 @@ blockToRST (Header level (name,classes,_) inlines) = do
|
|||
return $ nowrap $ hang 3 ".. " (rub $$ name' $$ cls) $$ blankline
|
||||
blockToRST (CodeBlock (_,classes,kvs) str) = do
|
||||
opts <- gets stOptions
|
||||
let tabstop = writerTabStop opts
|
||||
let startnum = maybe "" (\x -> " " <> text x) $ lookup "startFrom" kvs
|
||||
let numberlines = if "numberLines" `elem` classes
|
||||
then " :number-lines:" <> startnum
|
||||
|
@ -276,11 +275,10 @@ blockToRST (CodeBlock (_,classes,kvs) str) = do
|
|||
c `notElem` ["sourceCode","literate","numberLines"]] of
|
||||
[] -> "::"
|
||||
(lang:_) -> (".. code:: " <> text lang) $$ numberlines)
|
||||
$+$ nest tabstop (text str) $$ blankline
|
||||
$+$ nest 3 (text str) $$ blankline
|
||||
blockToRST (BlockQuote blocks) = do
|
||||
tabstop <- gets $ writerTabStop . stOptions
|
||||
contents <- blockListToRST blocks
|
||||
return $ nest tabstop contents <> blankline
|
||||
return $ nest 3 contents <> blankline
|
||||
blockToRST (Table caption aligns widths headers rows) = do
|
||||
caption' <- inlineListToRST caption
|
||||
let blocksToDoc opts bs = do
|
||||
|
@ -338,8 +336,7 @@ definitionListItemToRST :: PandocMonad m => ([Inline], [[Block]]) -> RST m Doc
|
|||
definitionListItemToRST (label, defs) = do
|
||||
label' <- inlineListToRST label
|
||||
contents <- liftM vcat $ mapM blockListToRST defs
|
||||
tabstop <- gets $ writerTabStop . stOptions
|
||||
return $ nowrap label' $$ nest tabstop (nestle contents <> cr)
|
||||
return $ nowrap label' $$ nest 3 (nestle contents <> cr)
|
||||
|
||||
-- | Format a list of lines as line block.
|
||||
linesToLineBlock :: PandocMonad m => [[Inline]] -> RST m Doc
|
||||
|
|
|
@ -24,23 +24,23 @@ tests = [ testGroup "rubrics"
|
|||
para $ text "baz"])] =?>
|
||||
unlines
|
||||
[ "foo"
|
||||
, " .. rubric:: bar"
|
||||
, " .. rubric:: bar"
|
||||
, ""
|
||||
, " baz"]
|
||||
, " baz"]
|
||||
, "in block quote" =:
|
||||
blockQuote (header 1 (text "bar")) =?>
|
||||
" .. rubric:: bar"
|
||||
" .. rubric:: bar"
|
||||
, "with id" =:
|
||||
blockQuote (headerWith ("foo",[],[]) 1 (text "bar")) =?>
|
||||
unlines
|
||||
[ " .. rubric:: bar"
|
||||
, " :name: foo"]
|
||||
[ " .. rubric:: bar"
|
||||
, " :name: foo"]
|
||||
, "with id class" =:
|
||||
blockQuote (headerWith ("foo",["baz"],[]) 1 (text "bar")) =?>
|
||||
unlines
|
||||
[ " .. rubric:: bar"
|
||||
, " :name: foo"
|
||||
, " :class: baz"]
|
||||
[ " .. rubric:: bar"
|
||||
, " :name: foo"
|
||||
, " :class: baz"]
|
||||
]
|
||||
, testGroup "ligatures" -- handling specific sequences of blocks
|
||||
[ "a list is closed by a comment before a quote" =: -- issue 4248
|
||||
|
@ -50,7 +50,7 @@ tests = [ testGroup "rubrics"
|
|||
, ""
|
||||
, ".."
|
||||
, ""
|
||||
, " quoted"]
|
||||
, " quoted"]
|
||||
]
|
||||
, testGroup "inlines"
|
||||
[ "are removed when empty" =: -- #4434
|
||||
|
|
|
@ -7,9 +7,9 @@ print("hello")
|
|||
^D
|
||||
.. code:: python
|
||||
|
||||
print("hello")
|
||||
print("hello")
|
||||
|
||||
..
|
||||
|
||||
block quote
|
||||
block quote
|
||||
````
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
,[BlockQuote
|
||||
[Para [Strong [Str "thisIsGoingToBeTooLongAnyway"]]]]]]]
|
||||
^D
|
||||
+-------+--------------------------------------+
|
||||
| one | two |
|
||||
+=======+======================================+
|
||||
| ports | **thisIsGoingToBeTooLongAnyway** |
|
||||
+-------+--------------------------------------+
|
||||
+-------+-------------------------------------+
|
||||
| one | two |
|
||||
+=======+=====================================+
|
||||
| ports | **thisIsGoingToBeTooLongAnyway** |
|
||||
+-------+-------------------------------------+
|
||||
```
|
||||
|
|
|
@ -6,9 +6,9 @@ return a single value:
|
|||
|
||||
.. code:: haskell
|
||||
|
||||
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
|
||||
unsplit = arr . uncurry
|
||||
-- arr (\op (x,y) -> x `op` y)
|
||||
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
|
||||
unsplit = arr . uncurry
|
||||
-- arr (\op (x,y) -> x `op` y)
|
||||
|
||||
``(***)`` combines two arrows into a new arrow by running the two arrows on a
|
||||
pair of values (one arrow on the first item of the pair and one arrow on the
|
||||
|
@ -16,8 +16,8 @@ second item of the pair).
|
|||
|
||||
::
|
||||
|
||||
f *** g = first f >>> second g
|
||||
f *** g = first f >>> second g
|
||||
|
||||
Block quote:
|
||||
|
||||
foo bar
|
||||
foo bar
|
||||
|
|
|
@ -14,8 +14,8 @@ second item of the pair).
|
|||
|
||||
::
|
||||
|
||||
f *** g = first f >>> second g
|
||||
f *** g = first f >>> second g
|
||||
|
||||
Block quote:
|
||||
|
||||
foo bar
|
||||
foo bar
|
||||
|
|
120
test/writer.rst
120
test/writer.rst
|
@ -69,30 +69,30 @@ Block Quotes
|
|||
|
||||
E-mail style:
|
||||
|
||||
This is a block quote. It is pretty short.
|
||||
This is a block quote. It is pretty short.
|
||||
|
||||
..
|
||||
|
||||
Code in a block quote:
|
||||
Code in a block quote:
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
sub status {
|
||||
print "working";
|
||||
}
|
||||
sub status {
|
||||
print "working";
|
||||
}
|
||||
|
||||
A list:
|
||||
A list:
|
||||
|
||||
1. item one
|
||||
2. item two
|
||||
1. item one
|
||||
2. item two
|
||||
|
||||
Nested block quotes:
|
||||
Nested block quotes:
|
||||
|
||||
nested
|
||||
nested
|
||||
|
||||
..
|
||||
..
|
||||
|
||||
nested
|
||||
nested
|
||||
|
||||
This should not be a block quote: 2 > 1.
|
||||
|
||||
|
@ -107,21 +107,21 @@ Code:
|
|||
|
||||
::
|
||||
|
||||
---- (should be four hyphens)
|
||||
---- (should be four hyphens)
|
||||
|
||||
sub status {
|
||||
print "working";
|
||||
}
|
||||
sub status {
|
||||
print "working";
|
||||
}
|
||||
|
||||
this code block is indented by one tab
|
||||
this code block is indented by one tab
|
||||
|
||||
And:
|
||||
|
||||
::
|
||||
|
||||
this code block is indented by two tabs
|
||||
this code block is indented by two tabs
|
||||
|
||||
These should not be escaped: \$ \\ \> \[ \{
|
||||
These should not be escaped: \$ \\ \> \[ \{
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -302,83 +302,83 @@ Definition Lists
|
|||
Tight using spaces:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
red fruit
|
||||
orange
|
||||
orange fruit
|
||||
orange fruit
|
||||
banana
|
||||
yellow fruit
|
||||
yellow fruit
|
||||
|
||||
Tight using tabs:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
red fruit
|
||||
orange
|
||||
orange fruit
|
||||
orange fruit
|
||||
banana
|
||||
yellow fruit
|
||||
yellow fruit
|
||||
|
||||
Loose:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
red fruit
|
||||
|
||||
orange
|
||||
orange fruit
|
||||
orange fruit
|
||||
|
||||
banana
|
||||
yellow fruit
|
||||
yellow fruit
|
||||
|
||||
Multiple blocks with italics:
|
||||
|
||||
*apple*
|
||||
red fruit
|
||||
red fruit
|
||||
|
||||
contains seeds, crisp, pleasant to taste
|
||||
contains seeds, crisp, pleasant to taste
|
||||
|
||||
*orange*
|
||||
orange fruit
|
||||
orange fruit
|
||||
|
||||
::
|
||||
::
|
||||
|
||||
{ orange code block }
|
||||
{ orange code block }
|
||||
|
||||
..
|
||||
..
|
||||
|
||||
orange block quote
|
||||
orange block quote
|
||||
|
||||
Multiple definitions, tight:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
computer
|
||||
red fruit
|
||||
computer
|
||||
orange
|
||||
orange fruit
|
||||
bank
|
||||
orange fruit
|
||||
bank
|
||||
|
||||
Multiple definitions, loose:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
red fruit
|
||||
|
||||
computer
|
||||
computer
|
||||
|
||||
orange
|
||||
orange fruit
|
||||
orange fruit
|
||||
|
||||
bank
|
||||
bank
|
||||
|
||||
Blank line after term, indented marker, alternate markers:
|
||||
|
||||
apple
|
||||
red fruit
|
||||
red fruit
|
||||
|
||||
computer
|
||||
computer
|
||||
|
||||
orange
|
||||
orange fruit
|
||||
orange fruit
|
||||
|
||||
1. sublist
|
||||
2. sublist
|
||||
1. sublist
|
||||
2. sublist
|
||||
|
||||
HTML Blocks
|
||||
===========
|
||||
|
@ -491,15 +491,15 @@ This should be a code block, though:
|
|||
|
||||
::
|
||||
|
||||
<div>
|
||||
foo
|
||||
</div>
|
||||
<div>
|
||||
foo
|
||||
</div>
|
||||
|
||||
As should this:
|
||||
|
||||
::
|
||||
|
||||
<div>foo</div>
|
||||
<div>foo</div>
|
||||
|
||||
Now, nested:
|
||||
|
||||
|
@ -554,7 +554,7 @@ Code block:
|
|||
|
||||
::
|
||||
|
||||
<!-- Comment -->
|
||||
<!-- Comment -->
|
||||
|
||||
Just plain comment, with trailing spaces on the line:
|
||||
|
||||
|
@ -566,7 +566,7 @@ Code:
|
|||
|
||||
::
|
||||
|
||||
<hr />
|
||||
<hr />
|
||||
|
||||
Hr’s:
|
||||
|
||||
|
@ -793,7 +793,7 @@ This should [not][] be a link.
|
|||
|
||||
::
|
||||
|
||||
[not]: /url
|
||||
[not]: /url
|
||||
|
||||
Foo `bar </url/>`__.
|
||||
|
||||
|
@ -822,13 +822,13 @@ With an ampersand: http://example.com/?foo=1&bar=2
|
|||
|
||||
An e-mail address: nobody@nowhere.net
|
||||
|
||||
Blockquoted: http://example.com/
|
||||
Blockquoted: http://example.com/
|
||||
|
||||
Auto-links should not occur here: ``<http://example.com/>``
|
||||
|
||||
::
|
||||
|
||||
or here: <http://example.com/>
|
||||
or here: <http://example.com/>
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -853,7 +853,7 @@ Here is a footnote reference, [1]_ and another. [2]_ This should *not* be a
|
|||
footnote reference, because it contains a space.[^my note] Here is an inline
|
||||
note. [3]_
|
||||
|
||||
Notes can go in quotes. [4]_
|
||||
Notes can go in quotes. [4]_
|
||||
|
||||
1. And in list items. [5]_
|
||||
|
||||
|
@ -871,7 +871,7 @@ This paragraph should not be part of the note, as it is not indented.
|
|||
|
||||
::
|
||||
|
||||
{ <code> }
|
||||
{ <code> }
|
||||
|
||||
If you want, you can indent every line, but you can also be lazy and just
|
||||
indent the first line of each block.
|
||||
|
|
Loading…
Add table
Reference in a new issue