Skip to content

Commit 229f339

Browse files
[improvements] The functionality of adding text has been improved.
1 parent 8c14219 commit 229f339

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/node_modules
2-
/package-lock.json
2+
/package-lock.json
3+
/test.js
4+
/style.css
5+
/index.html

elementOfHtml.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,33 @@ export class ElementOfHtml {
135135
this.text = entryRule.declarations.find(
136136
decl => decl.property == '--text'
137137
)?.value
138-
this.textBefore = entryRule.declarations.find(
139-
decl => decl.property == '--text-before'
140-
)?.value
141-
this.textAfter = entryRule.declarations.find(
142-
decl => decl.property == '--text-after'
143-
)?.value
144138

145139
// Removing extra quotes
146-
this.text = this?.text?.substring(1, this.text.length - 1)
147-
this.textBefore = this?.textBefore?.substring(1, this.textBefore.length - 1)
148-
this.textAfter = this?.textAfter?.substring(1, this.textAfter.length - 1)
140+
let splittedText = this.text
141+
.split(',')
142+
.map(str => str.trim().slice(1, -1))
143+
144+
switch (splittedText.length) {
145+
case 1:
146+
this.text = splittedText[0]
147+
break
148+
case 2:
149+
[this.text, this.textAfter] = splittedText
150+
break
151+
default:
152+
[this.textBefore, this.text, this.textAfter] = splittedText
153+
break
154+
}
155+
156+
this.textBefore ??= entryRule.declarations.find(
157+
decl => decl.property == '--text-before'
158+
)
159+
?.value.slice(1, -1)
160+
161+
this.textAfter ??= entryRule.declarations.find(
162+
decl => decl.property == '--text-after'
163+
)
164+
?.value.slice(1, -1)
149165
}
150166
#setParentAndSelfSelector(fullSelector) {
151167
let partsOfSelector = fullSelector.split(' ')
@@ -215,13 +231,9 @@ export class ElementOfHtml {
215231
name = declaration.property.replace('--', '')
216232
}
217233

218-
// Removing nested quotes
219-
if (
220-
declaration.value[0] == '"' ||
221-
declaration.value[0] == "'" ||
222-
declaration.value[0] == '`'
223-
) {
224-
value = declaration.value.substring(1, declaration.value.length - 1)
234+
if (/(")|(')|(`)/.test(declaration.value[0])) {
235+
// Removing nested quotes
236+
value = declaration.value.slice(1, -1)
225237
} else {
226238
value = declaration.value
227239
}

0 commit comments

Comments
 (0)