Skip to content

Commit 33e289d

Browse files
Changing the logic of processing comments with text
Now a single comment can contain text in several positions at once.
1 parent b462d3b commit 33e289d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

elementOfHtml.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,30 @@ export class ElementOfHtml {
153153
this.textAfter = this?.textAfter?.slice(1, -1)
154154
}
155155
#setTextFromComments(entryRule) {
156-
const replaceRegexp = / {1,}text(|-(before|after)): ?/
157-
158156
for (let decl of entryRule.declarations) {
159-
let textDeclaration = decl?.comment?.match(/text-(before|after):|text:/i)?.at(0)
160-
161-
if (!textDeclaration) continue
162-
163-
let position = textDeclaration.toLowerCase().replace(':', '')
164-
let text = decl.comment.replace(replaceRegexp, '')
165-
// Removing one mandatory space at the end
166-
.slice(0, -1)
167-
168-
switch (position) {
169-
case 'text':
170-
this.text = text
171-
break
172-
case 'text-before':
173-
this.textBefore = text
174-
break
175-
case 'text-after':
176-
this.textAfter = text
177-
break
157+
let textDeclarations = decl?.comment?.match(/@(inside|before|after)/gi)
158+
159+
if (!textDeclarations) continue
160+
161+
for (let declType of textDeclarations) {
162+
let position = declType.toLowerCase().replace('@', '')
163+
let text = decl.comment
164+
// Pulling text only for a specific position
165+
.match(new RegExp(`(?<=${position}).*? (?=@|$)`, 's'))[0]
166+
// Removing mandatory spaces at the beginning and at the end
167+
.slice(1, -1)
168+
169+
switch (position) {
170+
case 'inside':
171+
this.text = text
172+
break
173+
case 'before':
174+
this.textBefore = text
175+
break
176+
case 'after':
177+
this.textAfter = text
178+
break
179+
}
178180
}
179181
}
180182
}

0 commit comments

Comments
 (0)