Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/remark-parse/lib/util/get-indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function indentation(value) {
var character = value.charAt(index)
var stops = {}
var size
var lastIndent = 0

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

stops[indent] = index
while (lastIndent < indent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For spaces (i.e. with indent - lastIndent == 1), this is equivalent to just stops[indent]=index; lastIndent=indent

For tabs, this will create entries in stops for all intermediate indents since the last one. For example, if the last indentation point is 1 (a space), and the next indentation point is 5 (a tab follows the initial space), this will add stops 2, 3, 4 and 5 pointing to character 1 (the tab).

stops[++lastIndent] = index
}

character = value.charAt(++index)
}

Expand Down
15 changes: 1 addition & 14 deletions packages/remark-parse/lib/util/remove-indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var getIndent = require('./get-indentation')

module.exports = indentation

var tab = '\t'
var lineFeed = '\n'
var space = ' '
var exclamationMark = '!'
Expand All @@ -21,7 +20,6 @@ function indentation(value, maximum) {
var index
var indentation
var stops
var padding

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

Expand Down Expand Up @@ -56,18 +54,7 @@ function indentation(value, maximum) {
index--
}

if (
trim(values[position]).length !== 0 &&
minIndent &&
index !== minIndent
) {
padding = tab
} else {
padding = ''
}

values[position] =
padding + values[position].slice(index in stops ? stops[index] + 1 : 0)
values[position] = values[position].slice(stops[index] + 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed anymore because stops will now contain all indentation points, therefore index will never be different than minIndent.

}
}

Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/input/list-mixed-indentation.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Mixed spaces and tabs

- (item 1.) Minimum list, equivalent to two spaces
- (item 2.) indented with 1 space, not enough indentation to be a subitem
- (item 2.1.) indented with tab


- (item 1.) Minimum list, equivalent to two spaces
- (item 1.1.) indentend with 2 spaces
- (item 1.2.) indented with tab


- (item 1.) List with 1 extra space
- (item 1.1.) indentend with 3 spaces
- (item 1.2.) indented with tab


- (item 1.) List with 2 extra space, equivalent to 1 tab indentation
- (item 1.1.) indentend with 4 spaces
- (item 1.2.) indented with tab


- (item 1.) List with 1 tab, equivalent to 4 spaces
- (item 1.1.) indentend with 4 spaces
- (item 1.2.) indented with tab


- (item 1.) list with double indentation and mixed items
- (item 1.1.) normal indentation with 1 tab
- (item 1.1.1.) item with 4 spaces + 4 spaces
- (item 1.1.2.) item with tab + 4 spaces
- (item 1.1.3.) item with 4 spaces + tab
- (item 1.1.4.) item with tab + tab
- (item 1.1.5.) item with 2 spaces + tab + 2 spaces (nasty!)
Loading