Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions test/fixtures/tree/mixed-indentation.commonmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"children": [
{
"type": "text",
"value": "Very long\n\t\t\tparagraph",
"value": "Very long\n\tparagraph",
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 comes from trying to find the indentation of

- Very long
<tab><tab>paragraph

This text is the "internal" content, the content without the indentation.

The resulting should be

Very long
<tab>paragraph

as the - in the first line marks the indentation, that is matched by the first <tab> in the second line.

Making this changes in the fixture makes it more consistent with the rest of the rest of the mixed-indentation fixtures, in all flavours and list styles.

"position": {
"start": {
"line": 3,
Expand All @@ -66,7 +66,7 @@
"offset": 48
},
"indent": [
0
2
]
}
}
Expand All @@ -83,7 +83,7 @@
"offset": 48
},
"indent": [
0
2
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/tree/mixed-indentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"children": [
{
"type": "text",
"value": "Very long\n\t\t\tparagraph",
"value": "Very long\n\tparagraph",
"position": {
"start": {
"line": 3,
Expand All @@ -66,7 +66,7 @@
"offset": 48
},
"indent": [
0
2
]
}
}
Expand All @@ -83,7 +83,7 @@
"offset": 48
},
"indent": [
0
2
]
}
}
Expand Down
1 change: 1 addition & 0 deletions tmp3
Submodule tmp3 added at 1b56e9