mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
Mardkown writer: fix spacing issues with definition lists.
- Properly handle the case where the first item is an indented code block. (Closes #11542.) - Use correct indentation when `four_space_rule` extension is disabled.
This commit is contained in:
@@ -578,7 +578,10 @@ blockToMarkdown' opts (CodeBlock attribs str) = do
|
|||||||
tildes <> attrs <> cr <> literal str <> cr <> tildes <> blankline
|
tildes <> attrs <> cr <> literal str <> cr <> tildes <> blankline
|
||||||
_ | variant == Markua -> blankline <> attrsToMarkua opts attribs <> cr <> backticks <> cr <>
|
_ | variant == Markua -> blankline <> attrsToMarkua opts attribs <> cr <> backticks <> cr <>
|
||||||
literal str <> cr <> backticks <> cr <> blankline
|
literal str <> cr <> backticks <> cr <> blankline
|
||||||
| otherwise -> nest (writerTabStop opts) (literal str) <> blankline
|
| otherwise -> -- don't use nest: see #11542
|
||||||
|
let addIndent "" = "\n"
|
||||||
|
addIndent x = (T.replicate (writerTabStop opts) " ") <> x <> "\n"
|
||||||
|
in literal (mconcat $ map addIndent (T.lines str)) $$ blankline
|
||||||
where
|
where
|
||||||
endlineLen c = maybe 3 ((+1) . maximum) $ nonEmpty
|
endlineLen c = maybe 3 ((+1) . maximum) $ nonEmpty
|
||||||
[T.length ln
|
[T.length ln
|
||||||
@@ -862,8 +865,10 @@ definitionListItemToMarkdown opts (label, defs) = do
|
|||||||
_ -> ":"
|
_ -> ":"
|
||||||
let leadingChars = case tabStop of
|
let leadingChars = case tabStop of
|
||||||
-- Always use two leading characters for Markua
|
-- Always use two leading characters for Markua
|
||||||
n | n >= 2 && variant /= Markua -> n
|
n | variant == Markua -> 2
|
||||||
_ -> 2
|
| isEnabled Ext_four_space_rule opts
|
||||||
|
, n >= 2 -> n
|
||||||
|
| otherwise -> 2
|
||||||
let sps = literal $ T.replicate (leadingChars - 1) " "
|
let sps = literal $ T.replicate (leadingChars - 1) " "
|
||||||
let isTight = case defs of
|
let isTight = case defs of
|
||||||
((Plain _ : _): _) -> True
|
((Plain _ : _): _) -> True
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
```
|
||||||
|
% pandoc -f native -t markdown
|
||||||
|
[ DefinitionList
|
||||||
|
[ ( [ Str "Input" ]
|
||||||
|
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
^D
|
||||||
|
Input
|
||||||
|
|
||||||
|
: Term
|
||||||
|
|
||||||
|
: Def
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f markdown -t native
|
||||||
|
Input
|
||||||
|
|
||||||
|
: Term
|
||||||
|
|
||||||
|
: Def
|
||||||
|
^D
|
||||||
|
[ DefinitionList
|
||||||
|
[ ( [ Str "Input" ]
|
||||||
|
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f native -t markdown+four_space_rule
|
||||||
|
[ DefinitionList
|
||||||
|
[ ( [ Str "Input" ]
|
||||||
|
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
^D
|
||||||
|
Input
|
||||||
|
|
||||||
|
: Term
|
||||||
|
|
||||||
|
: Def
|
||||||
|
```
|
||||||
@@ -4,5 +4,5 @@
|
|||||||
: description
|
: description
|
||||||
^D
|
^D
|
||||||
1\. item
|
1\. item
|
||||||
: description
|
: description
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ Module FvwmAnimate \[ModuleAlias\]
|
|||||||
|
|
||||||
\*FvwmAnimate: Color color
|
\*FvwmAnimate: Color color
|
||||||
|
|
||||||
: Tells **FvwmAnimate** what color to draw with. The color is
|
: Tells **FvwmAnimate** what color to draw with. The color is
|
||||||
\"XOR\'ed\" (exclusive ORed) onto the background.
|
\"XOR\'ed\" (exclusive ORed) onto the background.
|
||||||
|
|
||||||
\*FvwmAnimate: Pixmap pixmap
|
\*FvwmAnimate: Pixmap pixmap
|
||||||
|
|
||||||
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
|
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
|
||||||
useful if **\*FvwmAnimate: Color** gives poor results.
|
useful if **\*FvwmAnimate: Color** gives poor results.
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ This is line two.
|
|||||||
|
|
||||||
**\--help**
|
**\--help**
|
||||||
|
|
||||||
: This is line one.
|
: This is line one.
|
||||||
|
|
||||||
This is line two.
|
This is line two.
|
||||||
```
|
```
|
||||||
|
|||||||
+27
-27
@@ -261,93 +261,93 @@ B. Williams
|
|||||||
Tight using spaces:
|
Tight using spaces:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
: yellow fruit
|
: yellow fruit
|
||||||
|
|
||||||
Tight using tabs:
|
Tight using tabs:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
: yellow fruit
|
: yellow fruit
|
||||||
|
|
||||||
Loose:
|
Loose:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
|
|
||||||
: yellow fruit
|
: yellow fruit
|
||||||
|
|
||||||
Multiple blocks with italics:
|
Multiple blocks with italics:
|
||||||
|
|
||||||
*apple*
|
*apple*
|
||||||
|
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
contains seeds, crisp, pleasant to taste
|
contains seeds, crisp, pleasant to taste
|
||||||
|
|
||||||
*orange*
|
*orange*
|
||||||
|
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
{ orange code block }
|
{ orange code block }
|
||||||
|
|
||||||
> orange block quote
|
> orange block quote
|
||||||
|
|
||||||
Multiple definitions, tight:
|
Multiple definitions, tight:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
: red fruit
|
: red fruit
|
||||||
: computer
|
: computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
: orange fruit
|
: orange fruit
|
||||||
: bank
|
: bank
|
||||||
|
|
||||||
Multiple definitions, loose:
|
Multiple definitions, loose:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
: computer
|
: computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
: bank
|
: bank
|
||||||
|
|
||||||
Blank line after term, indented marker, alternate markers:
|
Blank line after term, indented marker, alternate markers:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
: red fruit
|
: red fruit
|
||||||
|
|
||||||
: computer
|
: computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
: orange fruit
|
: orange fruit
|
||||||
|
|
||||||
1. sublist
|
1. sublist
|
||||||
2. sublist
|
2. sublist
|
||||||
|
|
||||||
# HTML Blocks
|
# HTML Blocks
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@
|
|||||||
<outline text="Fancy list markers" _note="(2) begins with 2 (3) and now 3 with a continuation iv. sublist with roman numerals, starting with 4 v. more items (A) a subsublist (B) a subsublist Nesting: A. Upper Alpha I. Upper Roman. (6) Decimal start with 6 c) Lower alpha with paren Autonumbering: 1. Autonumber. 2. More. 1. Nested. Should not be a list item: M.A. 2007 B. Williams --------------------------------------------------------------------------------">
|
<outline text="Fancy list markers" _note="(2) begins with 2 (3) and now 3 with a continuation iv. sublist with roman numerals, starting with 4 v. more items (A) a subsublist (B) a subsublist Nesting: A. Upper Alpha I. Upper Roman. (6) Decimal start with 6 c) Lower alpha with paren Autonumbering: 1. Autonumber. 2. More. 1. Nested. Should not be a list item: M.A. 2007 B. Williams --------------------------------------------------------------------------------">
|
||||||
</outline>
|
</outline>
|
||||||
</outline>
|
</outline>
|
||||||
<outline text="Definition Lists" _note="Tight using spaces: apple : red fruit orange : orange fruit banana : yellow fruit Tight using tabs: apple : red fruit orange : orange fruit banana : yellow fruit Loose: 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 { orange code block } > orange block quote Multiple definitions, tight: apple : red fruit : computer orange : orange fruit : bank Multiple definitions, loose: 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. sublist">
|
<outline text="Definition Lists" _note="Tight using spaces: apple : red fruit orange : orange fruit banana : yellow fruit Tight using tabs: apple : red fruit orange : orange fruit banana : yellow fruit Loose: 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 { orange code block } > orange block quote Multiple definitions, tight: apple : red fruit : computer orange : orange fruit : bank Multiple definitions, loose: 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. sublist">
|
||||||
</outline>
|
</outline>
|
||||||
<outline text="HTML Blocks" _note="Simple block on one line: ::: {} foo ::: And nested without indentation: :::::: {} :::: {} ::: {} foo ::: :::: ::: {} bar ::: :::::: Interpreted markdown in a table: <table> <tr> <td> This is *emphasized* </td> <td> And this is **strong** </td> </tr> </table> <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script> Here's a simple block: ::: {} foo ::: This should be a code block, though: <div> foo </div> As should this: <div>foo</div> Now, nested: ::::: {} :::: {} ::: {} foo ::: :::: ::::: This should just be an HTML comment: <!-- Comment --> Multiline: <!-- Blah Blah --> <!-- This is another comment. --> Code block: <!-- Comment --> Just plain comment, with trailing spaces on the line: <!-- foo --> Code: <hr /> Hr's: <hr> <hr /> <hr /> <hr> <hr /> <hr /> <hr class="foo" id="bar" /> <hr class="foo" id="bar" /> <hr class="foo" id="bar"> --------------------------------------------------------------------------------">
|
<outline text="HTML Blocks" _note="Simple block on one line: ::: {} foo ::: And nested without indentation: :::::: {} :::: {} ::: {} foo ::: :::: ::: {} bar ::: :::::: Interpreted markdown in a table: <table> <tr> <td> This is *emphasized* </td> <td> And this is **strong** </td> </tr> </table> <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script> Here's a simple block: ::: {} foo ::: This should be a code block, though: <div> foo </div> As should this: <div>foo</div> Now, nested: ::::: {} :::: {} ::: {} foo ::: :::: ::::: This should just be an HTML comment: <!-- Comment --> Multiline: <!-- Blah Blah --> <!-- This is another comment. --> Code block: <!-- Comment --> Just plain comment, with trailing spaces on the line: <!-- foo --> Code: <hr /> Hr's: <hr> <hr /> <hr /> <hr> <hr /> <hr /> <hr class="foo" id="bar" /> <hr class="foo" id="bar" /> <hr class="foo" id="bar"> --------------------------------------------------------------------------------">
|
||||||
</outline>
|
</outline>
|
||||||
|
|||||||
+27
-27
@@ -257,93 +257,93 @@ Definition Lists
|
|||||||
Tight using spaces:
|
Tight using spaces:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
yellow fruit
|
yellow fruit
|
||||||
|
|
||||||
Tight using tabs:
|
Tight using tabs:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
yellow fruit
|
yellow fruit
|
||||||
|
|
||||||
Loose:
|
Loose:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
banana
|
banana
|
||||||
|
|
||||||
yellow fruit
|
yellow fruit
|
||||||
|
|
||||||
Multiple blocks with italics:
|
Multiple blocks with italics:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
contains seeds, crisp, pleasant to taste
|
contains seeds, crisp, pleasant to taste
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
{ orange code block }
|
{ orange code block }
|
||||||
|
|
||||||
orange block quote
|
orange block quote
|
||||||
|
|
||||||
Multiple definitions, tight:
|
Multiple definitions, tight:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
red fruit
|
red fruit
|
||||||
computer
|
computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
orange fruit
|
orange fruit
|
||||||
bank
|
bank
|
||||||
|
|
||||||
Multiple definitions, loose:
|
Multiple definitions, loose:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
computer
|
computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
bank
|
bank
|
||||||
|
|
||||||
Blank line after term, indented marker, alternate markers:
|
Blank line after term, indented marker, alternate markers:
|
||||||
|
|
||||||
apple
|
apple
|
||||||
|
|
||||||
red fruit
|
red fruit
|
||||||
|
|
||||||
computer
|
computer
|
||||||
|
|
||||||
orange
|
orange
|
||||||
|
|
||||||
orange fruit
|
orange fruit
|
||||||
|
|
||||||
1. sublist
|
1. sublist
|
||||||
2. sublist
|
2. sublist
|
||||||
|
|
||||||
HTML Blocks
|
HTML Blocks
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user