Skip to content

Commit 23dcf61

Browse files
authored
correct whitespace handling (#66)
Fix #65
1 parent e15bec3 commit 23dcf61

File tree

14 files changed

+22945
-20028
lines changed

14 files changed

+22945
-20028
lines changed

packages/hast-util-from-webparser/package-lock.json

Lines changed: 75 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/prettyhtml-formatter/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ function format(options) {
164164
newline = true
165165
}
166166
child.value = child.value
167-
// remove leading and last tab characters
168-
.replace(/^[ \t]+|[ \t]+$/g, '')
169167
// reduce newlines to one newline
170168
// $& contains the lastMatch
171169
.replace(re, '$&' + repeat(indent, level))
@@ -225,6 +223,11 @@ function format(options) {
225223
(newline && index === 0) ||
226224
elementHasGap(prevChild)
227225
) {
226+
// we can remove the trailing whitespaces because
227+
// we will add a single newline
228+
if (is('text', prevChild)) {
229+
prevChild.value = prevChild.value.replace(/[ \t]+$/, '')
230+
}
228231
result.push({
229232
type: 'text',
230233
value: single + repeat(indent, indentLevel)

0 commit comments

Comments
 (0)