Added needed space after .bc and .bq.

Otherwise these can trap a </dd>, for example.

Better solution to try next: rewrite using Pretty.
This commit is contained in:
John MacFarlane 2011-01-23 10:08:11 -08:00
parent 16d4366431
commit 65a015e74b
3 changed files with 172 additions and 148 deletions

View file

@ -106,7 +106,7 @@ blockToTextile opts (Para inlines) = do
listLevel <- liftM stListLevel get listLevel <- liftM stListLevel get
contents <- inlineListToTextile opts inlines contents <- inlineListToTextile opts inlines
return $ if useTags return $ if useTags
then " <p>" ++ contents ++ "</p>" then "<p>" ++ contents ++ "</p>"
else contents ++ if null listLevel then "\n" else "" else contents ++ if null listLevel then "\n" else ""
blockToTextile _ (RawHtml str) = return str blockToTextile _ (RawHtml str) = return str
@ -126,14 +126,14 @@ blockToTextile _ (CodeBlock (_,classes,_) str) | any (all isSpace) (lines str) =
else " class=\"" ++ unwords classes ++ "\"" else " class=\"" ++ unwords classes ++ "\""
blockToTextile _ (CodeBlock (_,classes,_) str) = blockToTextile _ (CodeBlock (_,classes,_) str) =
return $ "bc" ++ classes' ++ ". " ++ str ++ "\n" return $ "bc" ++ classes' ++ ". " ++ str ++ "\n\n"
where classes' = if null classes where classes' = if null classes
then "" then ""
else "(" ++ unwords classes ++ ")" else "(" ++ unwords classes ++ ")"
blockToTextile opts (BlockQuote bs@[Para _]) = do blockToTextile opts (BlockQuote bs@[Para _]) = do
contents <- blockListToTextile opts bs contents <- blockListToTextile opts bs
return $ "bq. " ++ contents return $ "bq. " ++ contents ++ "\n\n"
blockToTextile opts (BlockQuote blocks) = do blockToTextile opts (BlockQuote blocks) = do
contents <- blockListToTextile opts blocks contents <- blockListToTextile opts blocks
@ -155,20 +155,20 @@ blockToTextile opts (Table capt aligns widths headers rows') = do
then return "" then return ""
else do else do
c <- inlineListToTextile opts capt c <- inlineListToTextile opts capt
return $ " <caption>" ++ c ++ "</caption>\n" return $ "<caption>" ++ c ++ "</caption>\n"
let percent w = show (truncate (100*w) :: Integer) ++ "%" let percent w = show (truncate (100*w) :: Integer) ++ "%"
let coltags = if all (== 0.0) widths let coltags = if all (== 0.0) widths
then "" then ""
else unlines $ map else unlines $ map
(\w -> " <col width=\"" ++ percent w ++ "\" />") widths (\w -> "<col width=\"" ++ percent w ++ "\" />") widths
head' <- if all null headers head' <- if all null headers
then return "" then return ""
else do else do
hs <- tableRowToTextile opts alignStrings 0 headers hs <- tableRowToTextile opts alignStrings 0 headers
return $ " <thead>\n" ++ hs ++ "\n </thead>\n" return $ "<thead>\n" ++ hs ++ "\n</thead>\n"
body' <- zipWithM (tableRowToTextile opts alignStrings) [1..] rows' body' <- zipWithM (tableRowToTextile opts alignStrings) [1..] rows'
return $ " <table>\n" ++ captionDoc ++ coltags ++ head' ++ return $ "<table>\n" ++ captionDoc ++ coltags ++ head' ++
" <tbody>\n" ++ unlines body' ++ " </tbody>\n </table>\n" "<tbody>\n" ++ unlines body' ++ "</tbody>\n</table>\n"
blockToTextile opts x@(BulletList items) = do blockToTextile opts x@(BulletList items) = do
oldUseTags <- liftM stUseTags get oldUseTags <- liftM stUseTags get
@ -176,7 +176,7 @@ blockToTextile opts x@(BulletList items) = do
if useTags if useTags
then do then do
contents <- withUseTags $ mapM (listItemToTextile opts) items contents <- withUseTags $ mapM (listItemToTextile opts) items
return $ " <ul>\n" ++ vcat contents ++ " </ul>\n" return $ "<ul>\n" ++ vcat contents ++ "\n</ul>\n"
else do else do
modify $ \s -> s { stListLevel = stListLevel s ++ "*" } modify $ \s -> s { stListLevel = stListLevel s ++ "*" }
level <- get >>= return . length . stListLevel level <- get >>= return . length . stListLevel
@ -190,8 +190,8 @@ blockToTextile opts x@(OrderedList attribs items) = do
if useTags if useTags
then do then do
contents <- withUseTags $ mapM (listItemToTextile opts) items contents <- withUseTags $ mapM (listItemToTextile opts) items
return $ " <ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++
" </ol>\n" "\n</ol>\n"
else do else do
modify $ \s -> s { stListLevel = stListLevel s ++ "#" } modify $ \s -> s { stListLevel = stListLevel s ++ "#" }
level <- get >>= return . length . stListLevel level <- get >>= return . length . stListLevel
@ -201,7 +201,7 @@ blockToTextile opts x@(OrderedList attribs items) = do
blockToTextile opts (DefinitionList items) = do blockToTextile opts (DefinitionList items) = do
contents <- withUseTags $ mapM (definitionListItemToTextile opts) items contents <- withUseTags $ mapM (definitionListItemToTextile opts) items
return $ " <dl>\n" ++ vcat contents ++ " </dl>\n" return $ "<dl>\n" ++ vcat contents ++ "\n</dl>\n"
-- Auxiliary functions for lists: -- Auxiliary functions for lists:
@ -222,7 +222,7 @@ listItemToTextile opts items = do
contents <- blockListToTextile opts items contents <- blockListToTextile opts items
useTags <- get >>= return . stUseTags useTags <- get >>= return . stUseTags
if useTags if useTags
then return $ " <li>" ++ contents ++ "</li>" then return $ "<li>" ++ contents ++ "</li>"
else do else do
marker <- get >>= return . stListLevel marker <- get >>= return . stListLevel
return $ marker ++ " " ++ contents return $ marker ++ " " ++ contents
@ -234,8 +234,8 @@ definitionListItemToTextile :: WriterOptions
definitionListItemToTextile opts (label, items) = do definitionListItemToTextile opts (label, items) = do
labelText <- inlineListToTextile opts label labelText <- inlineListToTextile opts label
contents <- mapM (blockListToTextile opts) items contents <- mapM (blockListToTextile opts) items
return $ " <dt>" ++ labelText ++ "</dt>\n" ++ return $ "<dt>" ++ labelText ++ "</dt>\n" ++
(intercalate "\n" $ map (\d -> " <dd>" ++ d ++ "</dd>") contents) (intercalate "\n" $ map (\d -> "<dd>" ++ d ++ "</dd>") contents)
-- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed. -- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed.
isSimpleList :: Block -> Bool isSimpleList :: Block -> Bool

View file

@ -1,16 +1,16 @@
Simple table with caption: Simple table with caption:
<table> <table>
<caption>Demonstration of simple table syntax.</caption> <caption>Demonstration of simple table syntax.</caption>
<thead> <thead>
<tr class="header"> <tr class="header">
<th align="right">Right</th> <th align="right">Right</th>
<th align="left">Left</th> <th align="left">Left</th>
<th align="center">Center</th> <th align="center">Center</th>
<th align="left">Default</th> <th align="left">Default</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="right">12</td> <td align="right">12</td>
<td align="left">12</td> <td align="left">12</td>
@ -29,21 +29,21 @@ Simple table with caption:
<td align="center">1</td> <td align="center">1</td>
<td align="left">1</td> <td align="left">1</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Simple table without caption: Simple table without caption:
<table> <table>
<thead> <thead>
<tr class="header"> <tr class="header">
<th align="right">Right</th> <th align="right">Right</th>
<th align="left">Left</th> <th align="left">Left</th>
<th align="center">Center</th> <th align="center">Center</th>
<th align="left">Default</th> <th align="left">Default</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="right">12</td> <td align="right">12</td>
<td align="left">12</td> <td align="left">12</td>
@ -62,22 +62,22 @@ Simple table without caption:
<td align="center">1</td> <td align="center">1</td>
<td align="left">1</td> <td align="left">1</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Simple table indented two spaces: Simple table indented two spaces:
<table> <table>
<caption>Demonstration of simple table syntax.</caption> <caption>Demonstration of simple table syntax.</caption>
<thead> <thead>
<tr class="header"> <tr class="header">
<th align="right">Right</th> <th align="right">Right</th>
<th align="left">Left</th> <th align="left">Left</th>
<th align="center">Center</th> <th align="center">Center</th>
<th align="left">Default</th> <th align="left">Default</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="right">12</td> <td align="right">12</td>
<td align="left">12</td> <td align="left">12</td>
@ -96,26 +96,26 @@ Simple table indented two spaces:
<td align="center">1</td> <td align="center">1</td>
<td align="left">1</td> <td align="left">1</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Multiline table with caption: Multiline table with caption:
<table> <table>
<caption>Here's the caption. It may span multiple lines.</caption> <caption>Here's the caption. It may span multiple lines.</caption>
<col width="15%" /> <col width="15%" />
<col width="13%" /> <col width="13%" />
<col width="16%" /> <col width="16%" />
<col width="33%" /> <col width="33%" />
<thead> <thead>
<tr class="header"> <tr class="header">
<th align="center">Centered Header</th> <th align="center">Centered Header</th>
<th align="left">Left Aligned</th> <th align="left">Left Aligned</th>
<th align="right">Right Aligned</th> <th align="right">Right Aligned</th>
<th align="left">Default aligned</th> <th align="left">Default aligned</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="center">First</td> <td align="center">First</td>
<td align="left">row</td> <td align="left">row</td>
@ -128,25 +128,25 @@ Multiline table with caption:
<td align="right">5.0</td> <td align="right">5.0</td>
<td align="left">Here's another one. Note the blank line between rows.</td> <td align="left">Here's another one. Note the blank line between rows.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Multiline table without caption: Multiline table without caption:
<table> <table>
<col width="15%" /> <col width="15%" />
<col width="13%" /> <col width="13%" />
<col width="16%" /> <col width="16%" />
<col width="33%" /> <col width="33%" />
<thead> <thead>
<tr class="header"> <tr class="header">
<th align="center">Centered Header</th> <th align="center">Centered Header</th>
<th align="left">Left Aligned</th> <th align="left">Left Aligned</th>
<th align="right">Right Aligned</th> <th align="right">Right Aligned</th>
<th align="left">Default aligned</th> <th align="left">Default aligned</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="center">First</td> <td align="center">First</td>
<td align="left">row</td> <td align="left">row</td>
@ -159,13 +159,13 @@ Multiline table without caption:
<td align="right">5.0</td> <td align="right">5.0</td>
<td align="left">Here's another one. Note the blank line between rows.</td> <td align="left">Here's another one. Note the blank line between rows.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Table without column headers: Table without column headers:
<table> <table>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="right">12</td> <td align="right">12</td>
<td align="left">12</td> <td align="left">12</td>
@ -184,17 +184,17 @@ Table without column headers:
<td align="center">1</td> <td align="center">1</td>
<td align="right">1</td> <td align="right">1</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Multiline table without column headers: Multiline table without column headers:
<table> <table>
<col width="15%" /> <col width="15%" />
<col width="13%" /> <col width="13%" />
<col width="16%" /> <col width="16%" />
<col width="33%" /> <col width="33%" />
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td align="center">First</td> <td align="center">First</td>
<td align="left">row</td> <td align="left">row</td>
@ -207,6 +207,6 @@ Multiline table without column headers:
<td align="right">5.0</td> <td align="right">5.0</td>
<td align="left">Here's another one. Note the blank line between rows.</td> <td align="left">Here's another one. Note the blank line between rows.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View file

@ -45,6 +45,8 @@ E-mail style:
bq. This is a block quote. It is pretty short. bq. This is a block quote. It is pretty short.
<blockquote> <blockquote>
Code in a block quote: Code in a block quote:
@ -62,8 +64,10 @@ Nested block quotes:
bq. nested bq. nested
bq. nested bq. nested
</blockquote> </blockquote>
This should not be a block quote: 2 &gt; 1. This should not be a block quote: 2 &gt; 1.
@ -164,11 +168,12 @@ and using spaces:
Multiple paragraphs: Multiple paragraphs:
<ol style="list-style-type: decimal;"> <ol style="list-style-type: decimal;">
<li> <p>Item 1, graf one.</p> <li><p>Item 1, graf one.</p>
<p>Item 1. graf two. The quick brown fox jumped over the lazy dog's back.</p></li> <p>Item 1. graf two. The quick brown fox jumped over the lazy dog's back.</p></li>
<li> <p>Item 2.</p></li> <li><p>Item 2.</p></li>
<li> <p>Item 3.</p></li> </ol> <li><p>Item 3.</p></li>
</ol>
h2. Nested h2. Nested
@ -203,32 +208,39 @@ h2. Tabs and spaces
h2. Fancy list markers h2. Fancy list markers
<ol start="2" style="list-style-type: decimal;"> <ol start="2" style="list-style-type: decimal;">
<li>begins with 2</li> <li>begins with 2</li>
<li> <p>and now 3</p> <li><p>and now 3</p>
<p>with a continuation</p> <p>with a continuation</p>
<ol start="4" style="list-style-type: lower-roman;"> <ol start="4" style="list-style-type: lower-roman;">
<li>sublist with roman numerals, starting with 4</li> <li>sublist with roman numerals, starting with 4</li>
<li>more items <li>more items
<ol style="list-style-type: upper-alpha;"> <ol style="list-style-type: upper-alpha;">
<li>a subsublist</li> <li>a subsublist</li>
<li>a subsublist</li> </ol> <li>a subsublist</li>
</li> </ol> </ol>
</li> </ol> </li>
</ol>
</li>
</ol>
Nesting: Nesting:
<ol style="list-style-type: upper-alpha;"> <ol style="list-style-type: upper-alpha;">
<li>Upper Alpha <li>Upper Alpha
<ol style="list-style-type: upper-roman;"> <ol style="list-style-type: upper-roman;">
<li>Upper Roman. <li>Upper Roman.
<ol start="6" style="list-style-type: decimal;"> <ol start="6" style="list-style-type: decimal;">
<li>Decimal start with 6 <li>Decimal start with 6
<ol start="3" style="list-style-type: lower-alpha;"> <ol start="3" style="list-style-type: lower-alpha;">
<li>Lower alpha with paren</li> </ol> <li>Lower alpha with paren</li>
</li> </ol> </ol>
</li> </ol> </li>
</li> </ol> </ol>
</li>
</ol>
</li>
</ol>
Autonumbering: Autonumbering:
@ -248,78 +260,88 @@ h1. Definition Lists
Tight using spaces: Tight using spaces:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd>red fruit</dd> <dd>red fruit</dd>
<dt>orange</dt> <dt>orange</dt>
<dd>orange fruit</dd> <dd>orange fruit</dd>
<dt>banana</dt> <dt>banana</dt>
<dd>yellow fruit</dd> </dl> <dd>yellow fruit</dd>
</dl>
Tight using tabs: Tight using tabs:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd>red fruit</dd> <dd>red fruit</dd>
<dt>orange</dt> <dt>orange</dt>
<dd>orange fruit</dd> <dd>orange fruit</dd>
<dt>banana</dt> <dt>banana</dt>
<dd>yellow fruit</dd> </dl> <dd>yellow fruit</dd>
</dl>
Loose: Loose:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd> <p>red fruit</p></dd> <dd><p>red fruit</p></dd>
<dt>orange</dt> <dt>orange</dt>
<dd> <p>orange fruit</p></dd> <dd><p>orange fruit</p></dd>
<dt>banana</dt> <dt>banana</dt>
<dd> <p>yellow fruit</p></dd> </dl> <dd><p>yellow fruit</p></dd>
</dl>
Multiple blocks with italics: Multiple blocks with italics:
<dl> <dl>
<dt>_apple_</dt> <dt>_apple_</dt>
<dd> <p>red fruit</p> <dd><p>red fruit</p>
<p>contains seeds, crisp, pleasant to taste</p></dd> <p>contains seeds, crisp, pleasant to taste</p></dd>
<dt>_orange_</dt> <dt>_orange_</dt>
<dd> <p>orange fruit</p> <dd><p>orange fruit</p>
bc. { orange code block } bc. { orange code block }
bq. <p>orange block quote</p></dd> </dl> bq. <p>orange block quote</p>
</dd>
</dl>
Multiple definitions, tight: Multiple definitions, tight:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd>red fruit</dd> <dd>red fruit</dd>
<dd>computer</dd> <dd>computer</dd>
<dt>orange</dt> <dt>orange</dt>
<dd>orange fruit</dd> <dd>orange fruit</dd>
<dd>bank</dd> </dl> <dd>bank</dd>
</dl>
Multiple definitions, loose: Multiple definitions, loose:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd> <p>red fruit</p></dd> <dd><p>red fruit</p></dd>
<dd> <p>computer</p></dd> <dd><p>computer</p></dd>
<dt>orange</dt> <dt>orange</dt>
<dd> <p>orange fruit</p></dd> <dd><p>orange fruit</p></dd>
<dd> <p>bank</p></dd> </dl> <dd><p>bank</p></dd>
</dl>
Blank line after term, indented marker, alternate markers: Blank line after term, indented marker, alternate markers:
<dl> <dl>
<dt>apple</dt> <dt>apple</dt>
<dd> <p>red fruit</p></dd> <dd><p>red fruit</p></dd>
<dd> <p>computer</p></dd> <dd><p>computer</p></dd>
<dt>orange</dt> <dt>orange</dt>
<dd> <p>orange fruit</p> <dd><p>orange fruit</p>
<ol style="list-style-type: decimal;"> <ol style="list-style-type: decimal;">
<li>sublist</li> <li>sublist</li>
<li>sublist</li> </ol> <li>sublist</li>
</dd> </dl> </ol>
</dd>
</dl>
h1. HTML Blocks 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/ bq. Blockquoted: "http://example.com/":http://example.com/
Auto-links should not occur here: @<http://example.com/>@ Auto-links should not occur here: @<http://example.com/>@
bc. or here: <http://example.com/> bc. or here: <http://example.com/>
@ -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] bq. Notes can go in quotes.[4]
# And in list items.[5] # And in list items.[5]
This paragraph should not be part of the note, as it is not indented. This paragraph should not be part of the note, as it is not indented.