Skip to content

Commit 0697d46

Browse files
authored
Fix lists with mixed indentation
Closes GH-198. Closes GH-485.
1 parent ac90c03 commit 0697d46

File tree

7 files changed

+3164
-21
lines changed

7 files changed

+3164
-21
lines changed

packages/remark-parse/lib/util/get-indentation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function indentation(value) {
1515
var character = value.charAt(index)
1616
var stops = {}
1717
var size
18+
var lastIndent = 0
1819

1920
while (character === tab || character === space) {
2021
size = character === tab ? tabSize : spaceSize
@@ -25,7 +26,10 @@ function indentation(value) {
2526
indent = Math.floor(indent / size) * size
2627
}
2728

28-
stops[indent] = index
29+
while (lastIndent < indent) {
30+
stops[++lastIndent] = index
31+
}
32+
2933
character = value.charAt(++index)
3034
}
3135

packages/remark-parse/lib/util/remove-indentation.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var getIndent = require('./get-indentation')
66

77
module.exports = indentation
88

9-
var tab = '\t'
109
var lineFeed = '\n'
1110
var space = ' '
1211
var exclamationMark = '!'
@@ -21,7 +20,6 @@ function indentation(value, maximum) {
2120
var index
2221
var indentation
2322
var stops
24-
var padding
2523

2624
values.unshift(repeat(space, maximum) + exclamationMark)
2725

@@ -56,18 +54,7 @@ function indentation(value, maximum) {
5654
index--
5755
}
5856

59-
if (
60-
trim(values[position]).length !== 0 &&
61-
minIndent &&
62-
index !== minIndent
63-
) {
64-
padding = tab
65-
} else {
66-
padding = ''
67-
}
68-
69-
values[position] =
70-
padding + values[position].slice(index in stops ? stops[index] + 1 : 0)
57+
values[position] = values[position].slice(stops[index] + 1)
7158
}
7259
}
7360

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Mixed spaces and tabs
2+
3+
- (item 1.) Minimum list, equivalent to two spaces
4+
- (item 2.) indented with 1 space, not enough indentation to be a subitem
5+
- (item 2.1.) indented with tab
6+
7+
8+
- (item 1.) Minimum list, equivalent to two spaces
9+
- (item 1.1.) indentend with 2 spaces
10+
- (item 1.2.) indented with tab
11+
12+
13+
- (item 1.) List with 1 extra space
14+
- (item 1.1.) indentend with 3 spaces
15+
- (item 1.2.) indented with tab
16+
17+
18+
- (item 1.) List with 2 extra space, equivalent to 1 tab indentation
19+
- (item 1.1.) indentend with 4 spaces
20+
- (item 1.2.) indented with tab
21+
22+
23+
- (item 1.) List with 1 tab, equivalent to 4 spaces
24+
- (item 1.1.) indentend with 4 spaces
25+
- (item 1.2.) indented with tab
26+
27+
28+
- (item 1.) list with double indentation and mixed items
29+
- (item 1.1.) normal indentation with 1 tab
30+
- (item 1.1.1.) item with 4 spaces + 4 spaces
31+
- (item 1.1.2.) item with tab + 4 spaces
32+
- (item 1.1.3.) item with 4 spaces + tab
33+
- (item 1.1.4.) item with tab + tab
34+
- (item 1.1.5.) item with 2 spaces + tab + 2 spaces (nasty!)

0 commit comments

Comments
 (0)