From 65a015e74b326ca1bf88cf458629726a801d2fa3 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 23 Jan 2011 10:08:11 -0800 Subject: [PATCH] Added needed space after .bc and .bq. Otherwise these can trap a , for example. Better solution to try next: rewrite using Pretty. --- src/Text/Pandoc/Writers/Textile.hs | 30 ++--- tests/tables.textile | 106 ++++++++--------- tests/writer.textile | 184 ++++++++++++++++------------- 3 files changed, 172 insertions(+), 148 deletions(-) diff --git a/src/Text/Pandoc/Writers/Textile.hs b/src/Text/Pandoc/Writers/Textile.hs index 0987e1314..cab582fc3 100644 --- a/src/Text/Pandoc/Writers/Textile.hs +++ b/src/Text/Pandoc/Writers/Textile.hs @@ -106,7 +106,7 @@ blockToTextile opts (Para inlines) = do listLevel <- liftM stListLevel get contents <- inlineListToTextile opts inlines return $ if useTags - then "

" ++ contents ++ "

" + then "

" ++ contents ++ "

" else contents ++ if null listLevel then "\n" else "" blockToTextile _ (RawHtml str) = return str @@ -126,14 +126,14 @@ blockToTextile _ (CodeBlock (_,classes,_) str) | any (all isSpace) (lines str) = else " class=\"" ++ unwords classes ++ "\"" blockToTextile _ (CodeBlock (_,classes,_) str) = - return $ "bc" ++ classes' ++ ". " ++ str ++ "\n" + return $ "bc" ++ classes' ++ ". " ++ str ++ "\n\n" where classes' = if null classes then "" else "(" ++ unwords classes ++ ")" blockToTextile opts (BlockQuote bs@[Para _]) = do contents <- blockListToTextile opts bs - return $ "bq. " ++ contents + return $ "bq. " ++ contents ++ "\n\n" blockToTextile opts (BlockQuote blocks) = do contents <- blockListToTextile opts blocks @@ -155,20 +155,20 @@ blockToTextile opts (Table capt aligns widths headers rows') = do then return "" else do c <- inlineListToTextile opts capt - return $ " " ++ c ++ "\n" + return $ "" ++ c ++ "\n" let percent w = show (truncate (100*w) :: Integer) ++ "%" let coltags = if all (== 0.0) widths then "" else unlines $ map - (\w -> " ") widths + (\w -> "") widths head' <- if all null headers then return "" else do hs <- tableRowToTextile opts alignStrings 0 headers - return $ " \n" ++ hs ++ "\n \n" + return $ "\n" ++ hs ++ "\n\n" body' <- zipWithM (tableRowToTextile opts alignStrings) [1..] rows' - return $ " \n" ++ captionDoc ++ coltags ++ head' ++ - " \n" ++ unlines body' ++ " \n
\n" + return $ "\n" ++ captionDoc ++ coltags ++ head' ++ + "\n" ++ unlines body' ++ "\n
\n" blockToTextile opts x@(BulletList items) = do oldUseTags <- liftM stUseTags get @@ -176,7 +176,7 @@ blockToTextile opts x@(BulletList items) = do if useTags then do contents <- withUseTags $ mapM (listItemToTextile opts) items - return $ " \n" + return $ "\n" else do modify $ \s -> s { stListLevel = stListLevel s ++ "*" } level <- get >>= return . length . stListLevel @@ -190,8 +190,8 @@ blockToTextile opts x@(OrderedList attribs items) = do if useTags then do contents <- withUseTags $ mapM (listItemToTextile opts) items - return $ " \n" ++ vcat contents ++ - " \n" + return $ "\n" ++ vcat contents ++ + "\n\n" else do modify $ \s -> s { stListLevel = stListLevel s ++ "#" } level <- get >>= return . length . stListLevel @@ -201,7 +201,7 @@ blockToTextile opts x@(OrderedList attribs items) = do blockToTextile opts (DefinitionList items) = do contents <- withUseTags $ mapM (definitionListItemToTextile opts) items - return $ "
\n" ++ vcat contents ++ "
\n" + return $ "
\n" ++ vcat contents ++ "\n
\n" -- Auxiliary functions for lists: @@ -222,7 +222,7 @@ listItemToTextile opts items = do contents <- blockListToTextile opts items useTags <- get >>= return . stUseTags if useTags - then return $ "
  • " ++ contents ++ "
  • " + then return $ "
  • " ++ contents ++ "
  • " else do marker <- get >>= return . stListLevel return $ marker ++ " " ++ contents @@ -234,8 +234,8 @@ definitionListItemToTextile :: WriterOptions definitionListItemToTextile opts (label, items) = do labelText <- inlineListToTextile opts label contents <- mapM (blockListToTextile opts) items - return $ "
    " ++ labelText ++ "
    \n" ++ - (intercalate "\n" $ map (\d -> "
    " ++ d ++ "
    ") contents) + return $ "
    " ++ labelText ++ "
    \n" ++ + (intercalate "\n" $ map (\d -> "
    " ++ d ++ "
    ") contents) -- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed. isSimpleList :: Block -> Bool diff --git a/tests/tables.textile b/tests/tables.textile index ccb34cf58..4836ecd79 100644 --- a/tests/tables.textile +++ b/tests/tables.textile @@ -1,16 +1,16 @@ Simple table with caption: - - - +
    Demonstration of simple table syntax.
    + + - - + + @@ -29,21 +29,21 @@ Simple table with caption: - -
    Demonstration of simple table syntax.
    Right Left Center Default
    12 121 1
    + + Simple table without caption: - - +
    + - - + + @@ -62,22 +62,22 @@ Simple table without caption: - -
    Right Left Center Default
    12 121 1
    + + Simple table indented two spaces: - - - +
    Demonstration of simple table syntax.
    + + - - + + @@ -96,26 +96,26 @@ Simple table indented two spaces: - -
    Demonstration of simple table syntax.
    Right Left Center Default
    12 121 1
    + + Multiline table with caption: - - - - - - - +
    Here's the caption. It may span multiple lines.
    + +++++ - - + + @@ -128,25 +128,25 @@ Multiline table with caption: - -
    Here's the caption. It may span multiple lines.
    Centered Header Left Aligned Right Aligned Default aligned
    First row5.0 Here's another one. Note the blank line between rows.
    + + Multiline table without caption: - - - - - - +
    +++++ - - + + @@ -159,13 +159,13 @@ Multiline table without caption: - -
    Centered Header Left Aligned Right Aligned Default aligned
    First row5.0 Here's another one. Note the blank line between rows.
    + + Table without column headers: - - +
    + @@ -184,17 +184,17 @@ Table without column headers: - -
    12 121 1
    + + Multiline table without column headers: - - - - - - +
    +++++ @@ -207,6 +207,6 @@ Multiline table without column headers: - -
    First row5.0 Here's another one. Note the blank line between rows.
    + + diff --git a/tests/writer.textile b/tests/writer.textile index f3513884a..a794a55a8 100644 --- a/tests/writer.textile +++ b/tests/writer.textile @@ -45,6 +45,8 @@ E-mail style: bq. This is a block quote. It is pretty short. + +
    Code in a block quote: @@ -62,8 +64,10 @@ Nested block quotes: bq. nested + bq. nested +
    This should not be a block quote: 2 > 1. @@ -164,11 +168,12 @@ and using spaces: Multiple paragraphs: -
      -
    1. Item 1, graf one.

      -

      Item 1. graf two. The quick brown fox jumped over the lazy dog's back.

    2. -
    3. Item 2.

    4. -
    5. Item 3.

    +
      +
    1. Item 1, graf one.

      +

      Item 1. graf two. The quick brown fox jumped over the lazy dog's back.

    2. +
    3. Item 2.

    4. +
    5. Item 3.

    6. +
    h2. Nested @@ -203,32 +208,39 @@ h2. Tabs and spaces h2. Fancy list markers -
      -
    1. begins with 2
    2. -
    3. and now 3

      -

      with a continuation

      -
        -
      1. sublist with roman numerals, starting with 4
      2. -
      3. more items -
          -
        1. a subsublist
        2. -
        3. a subsublist
        -
      -
    +
      +
    1. begins with 2
    2. +
    3. and now 3

      +

      with a continuation

      +
        +
      1. sublist with roman numerals, starting with 4
      2. +
      3. more items +
          +
        1. a subsublist
        2. +
        3. a subsublist
        4. +
        +
      4. +
      +
    4. +
    Nesting: -
      -
    1. Upper Alpha -
        -
      1. Upper Roman. -
          -
        1. Decimal start with 6 -
            -
          1. Lower alpha with paren
          -
        -
      -
    +
      +
    1. Upper Alpha +
        +
      1. Upper Roman. +
          +
        1. Decimal start with 6 +
            +
          1. Lower alpha with paren
          2. +
          +
        2. +
        +
      2. +
      +
    2. +
    Autonumbering: @@ -248,78 +260,88 @@ h1. Definition Lists Tight using spaces: -
    -
    apple
    -
    red fruit
    -
    orange
    -
    orange fruit
    -
    banana
    -
    yellow fruit
    +
    +
    apple
    +
    red fruit
    +
    orange
    +
    orange fruit
    +
    banana
    +
    yellow fruit
    +
    Tight using tabs: -
    -
    apple
    -
    red fruit
    -
    orange
    -
    orange fruit
    -
    banana
    -
    yellow fruit
    +
    +
    apple
    +
    red fruit
    +
    orange
    +
    orange fruit
    +
    banana
    +
    yellow fruit
    +
    Loose: -
    -
    apple
    -

    red fruit

    -
    orange
    -

    orange fruit

    -
    banana
    -

    yellow fruit

    +
    +
    apple
    +

    red fruit

    +
    orange
    +

    orange fruit

    +
    banana
    +

    yellow fruit

    +
    Multiple blocks with italics: -
    -
    _apple_
    -

    red fruit

    -

    contains seeds, crisp, pleasant to taste

    -
    _orange_
    -

    orange fruit

    +
    +
    _apple_
    +

    red fruit

    +

    contains seeds, crisp, pleasant to taste

    +
    _orange_
    +

    orange fruit

    bc. { orange code block } -bq.

    orange block quote

    +bq.

    orange block quote

    + +
    +
    Multiple definitions, tight: -
    -
    apple
    -
    red fruit
    -
    computer
    -
    orange
    -
    orange fruit
    -
    bank
    +
    +
    apple
    +
    red fruit
    +
    computer
    +
    orange
    +
    orange fruit
    +
    bank
    +
    Multiple definitions, loose: -
    -
    apple
    -

    red fruit

    -

    computer

    -
    orange
    -

    orange fruit

    -

    bank

    +
    +
    apple
    +

    red fruit

    +

    computer

    +
    orange
    +

    orange fruit

    +

    bank

    +
    Blank line after term, indented marker, alternate markers: -
    -
    apple
    -

    red fruit

    -

    computer

    -
    orange
    -

    orange fruit

    -
      -
    1. sublist
    2. -
    3. sublist
    -
    +
    +
    apple
    +

    red fruit

    +

    computer

    +
    orange
    +

    orange fruit

    +
      +
    1. sublist
    2. +
    3. sublist
    4. +
    +
    +
    h1. HTML Blocks @@ -630,6 +652,7 @@ An e-mail address: "nobody@nowhere.net":mailto:nobody@nowhere.net bq. Blockquoted: "http://example.com/":http://example.com/ + Auto-links should not occur here: @@ bc. or here: @@ -653,6 +676,7 @@ Here is a footnote reference,[1] and another.[2] This should _not_ be a footnote bq. Notes can go in quotes.[4] + # And in list items.[5] This paragraph should not be part of the note, as it is not indented.