diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2018-04-19 13:47:16 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2018-04-19 13:47:16 -0700 | 
| commit | 276894a2f2f7421c3470a4d50af94774ebef62d7 (patch) | |
| tree | 0a063e23dc4b604076041a75ee6035bb2c626ffc | |
| parent | c76565bef5ecdbf1173d23b79dda59df4120cdb9 (diff) | |
| download | pandoc-276894a2f2f7421c3470a4d50af94774ebef62d7.tar.gz | |
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.
| -rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 9 | ||||
| -rw-r--r-- | test/Tests/Writers/RST.hs | 18 | ||||
| -rw-r--r-- | test/command/3675.md | 4 | ||||
| -rw-r--r-- | test/command/4320.md | 10 | ||||
| -rw-r--r-- | test/lhs-test.rst | 10 | ||||
| -rw-r--r-- | test/lhs-test.rst+lhs | 4 | ||||
| -rw-r--r-- | test/writer.rst | 120 | 
7 files changed, 86 insertions, 89 deletions
| diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 74fc4dca4..cc7131d0a 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -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 diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs index 64367a108..29c9328f6 100644 --- a/test/Tests/Writers/RST.hs +++ b/test/Tests/Writers/RST.hs @@ -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 diff --git a/test/command/3675.md b/test/command/3675.md index b129c7a63..f75721b56 100644 --- a/test/command/3675.md +++ b/test/command/3675.md @@ -7,9 +7,9 @@ print("hello")  ^D  .. code:: python -    print("hello") +   print("hello")  .. -    block quote +   block quote  ```` diff --git a/test/command/4320.md b/test/command/4320.md index 5b0eeb5c1..732b30a3e 100644 --- a/test/command/4320.md +++ b/test/command/4320.md @@ -7,9 +7,9 @@    ,[BlockQuote      [Para [Strong [Str "thisIsGoingToBeTooLongAnyway"]]]]]]]  ^D -+-------+--------------------------------------+ -| one   | two                                  | -+=======+======================================+ -| ports |     **thisIsGoingToBeTooLongAnyway** | -+-------+--------------------------------------+ ++-------+-------------------------------------+ +| one   | two                                 | ++=======+=====================================+ +| ports |    **thisIsGoingToBeTooLongAnyway** | ++-------+-------------------------------------+  ``` diff --git a/test/lhs-test.rst b/test/lhs-test.rst index 3de2d9ff6..4d012a9f9 100644 --- a/test/lhs-test.rst +++ b/test/lhs-test.rst @@ -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 diff --git a/test/lhs-test.rst+lhs b/test/lhs-test.rst+lhs index eec79c546..6196c39ab 100644 --- a/test/lhs-test.rst+lhs +++ b/test/lhs-test.rst+lhs @@ -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 diff --git a/test/writer.rst b/test/writer.rst index 93158f0c3..3353d11d3 100644 --- a/test/writer.rst +++ b/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. | 
