Skip to content

Commit 92067e3

Browse files
The formatter has been changed
1 parent 0be1aaf commit 92067e3

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/package-lock.json

cssToHtml.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs-extra'
22
import path from 'path'
3-
import beautify from 'js-beautify'
3+
import prettier from "@prettier/sync"
44
import { parse } from '@adobe/css-tools'
55
import { createParser } from 'css-selector-parser'
66
import { ElementOfHtml } from './elementOfHtml.js'
@@ -28,18 +28,12 @@ export class CssToHtml {
2828
#elements = []
2929
#writeBefore
3030
#writeAfter
31-
#formatterOptions = {
32-
indent_size: 2,
33-
max_preserve_newlines: -1,
34-
preserve_newlines: false,
35-
}
3631
#writeInFile = false
3732
outputHTML
3833

39-
constructor({ css, formatterOptions, write, }) {
34+
constructor({ css, write, format = true, }) {
4035
this.#css = css
41-
42-
this.#formatterOptions = Object.assign(this.#formatterOptions, formatterOptions)
36+
this.format = format
4337

4438
if (write?.in) {
4539
this.#pathToHTML = path.normalize(write.in)
@@ -118,7 +112,11 @@ export class CssToHtml {
118112
}
119113
}
120114

121-
return beautify.html(newContent, this.#formatterOptions)
115+
if (this.format) {
116+
return prettier.format(newContent, { parser: "html" })
117+
} else {
118+
return newContent
119+
}
122120
}
123121
#containsUnacceptableSelector(selector) {
124122
return CssToHtml.UNACCEPTABLE_SELECTORS.some(

elementOfHtml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export class ElementOfHtml {
7373
endOfString
7474
}
7575
#addTextBefore() {
76-
this.#string += this.textBefore ? `${this.textBefore}` : ''
76+
this.#string += this.textBefore ? ` ${this.textBefore}` : ''
7777
}
7878
#addTextAfter() {
7979
this.#string += this.textAfter ? `${this.textAfter}` : ''
8080
}
8181
#addText() {
82-
this.#string += this.text ? `\n${this.text}` : ''
82+
this.#string += this.text ? `${this.text}` : ''
8383
}
8484
#addInnerElements() {
8585
for (let innerElement of this.innerElements) {
@@ -88,7 +88,7 @@ export class ElementOfHtml {
8888
}
8989
#createEndString() {
9090
if (!this.#selfCloseTag) {
91-
this.#string += '\n</' + this.tag + '>'
91+
this.#string += '</' + this.tag + '>'
9292
}
9393
}
9494
searchInnerElements(elements, searchIndex) {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"node"
2626
],
2727
"dependencies": {
28-
"fs-extra": "^11.2.0",
29-
"js-beautify": "^1.15.1",
3028
"@adobe/css-tools": "^4.4.0",
31-
"css-selector-parser": "^3.0.5"
29+
"@prettier/sync": "^0.5.2",
30+
"css-selector-parser": "^3.0.5",
31+
"fs-extra": "^11.2.0"
3232
},
3333
"license": "ISC"
3434
}

0 commit comments

Comments
 (0)