Skip to content

Commit bde1a00

Browse files
Improved text processing.
Now if there is a space without text before and after the curly braces, it will be ignored.
1 parent 08f1de3 commit bde1a00

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

elementOfHtml.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,22 @@ export class ElementOfHtml {
169169
// Removing spaces necessary for readability of a comment
170170
commentWithText = commentWithText.slice(1, -1)
171171

172-
let textBefore = commentWithText.match(/^.*(?={{)/s)?.at(0)
173-
let text = commentWithText.match(/(?<={{).*?(?=}}|$)/s)?.at(0)
174-
let textAfter = commentWithText.match(/(?<=}}).*$/s)?.at(0)
172+
let text = [
173+
// Get everything up to {{
174+
commentWithText.match(/^.*(?={{)/s)?.at(0),
175+
// Get everything in {{ }}
176+
commentWithText.match(/(?<={{).*?(?=}}|$)/s)?.at(0),
177+
// Get everything after }}
178+
commentWithText.match(/(?<=}}).*$/s)?.at(0)
179+
]
180+
181+
for (let i = 0; i < text.length; i++) {
182+
if (!text[i]?.trim()) {
183+
text[i] = ''
184+
}
185+
}
175186

176-
this.textBefore = textBefore
177-
this.text = text
178-
this.textAfter = textAfter
187+
[this.textBefore, this.text, this.textAfter] = text
179188
}
180189
#setParentAndSelfSelector(fullSelector) {
181190
let partsOfSelector = fullSelector.split(' ')

tests/text.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ test('New lines are placed correctly', () => {
66
assert.equal(
77
new CssToHtml({
88
css: `
9-
div { /* {{ text inside }} */ }
9+
div { /*
10+
{{ text inside }}
11+
12+
*/ }
1013
div i { /* {{ text of i }} after */ }
1114
`,
1215
})

0 commit comments

Comments
 (0)