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
|
||||
_ | variant == Markua -> blankline <> attrsToMarkua opts attribs <> cr <> backticks <> cr <>
|
||||
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
|
||||
endlineLen c = maybe 3 ((+1) . maximum) $ nonEmpty
|
||||
[T.length ln
|
||||
@@ -862,8 +865,10 @@ definitionListItemToMarkdown opts (label, defs) = do
|
||||
_ -> ":"
|
||||
let leadingChars = case tabStop of
|
||||
-- Always use two leading characters for Markua
|
||||
n | n >= 2 && variant /= Markua -> n
|
||||
_ -> 2
|
||||
n | variant == Markua -> 2
|
||||
| isEnabled Ext_four_space_rule opts
|
||||
, n >= 2 -> n
|
||||
| otherwise -> 2
|
||||
let sps = literal $ T.replicate (leadingChars - 1) " "
|
||||
let isTight = case defs of
|
||||
((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
|
||||
^D
|
||||
1\. item
|
||||
: description
|
||||
: description
|
||||
```
|
||||
|
||||
@@ -27,13 +27,13 @@ Module FvwmAnimate \[ModuleAlias\]
|
||||
|
||||
\*FvwmAnimate: Color color
|
||||
|
||||
: Tells **FvwmAnimate** what color to draw with. The color is
|
||||
\"XOR\'ed\" (exclusive ORed) onto the background.
|
||||
: Tells **FvwmAnimate** what color to draw with. The color is
|
||||
\"XOR\'ed\" (exclusive ORed) onto the background.
|
||||
|
||||
\*FvwmAnimate: Pixmap pixmap
|
||||
|
||||
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
|
||||
useful if **\*FvwmAnimate: Color** gives poor results.
|
||||
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
|
||||
useful if **\*FvwmAnimate: Color** gives poor results.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@ This is line two.
|
||||
|
||||
**\--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:
|
||||
|
||||
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
|
||||
|
||||
|
||||
+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>
|
||||
</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 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>
|
||||
|
||||
+27
-27
@@ -257,93 +257,93 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user