Skip to content

Commit ff4ea00

Browse files
committed
refactor index.js
1 parent e13e337 commit ff4ea00

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@egoistdeveloper/twcss-to-sass",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "HTML template to SASS converter for TailwindCSS",
55
"source": "src/index.js",
66
"main": "dist/twcss-to-sass.js",

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const formatterOptions = {
3434
indent_empty_lines: false
3535
};
3636

37+
3738
/**
3839
* Extract target attributes
3940
*
@@ -86,13 +87,13 @@ const getStyleContents = function (styleElements) {
8687
};
8788

8889
/**
89-
* Parse given HTML content as JSON
90+
* Filter given HTML content as JSON
9091
*
9192
* @param {string} htmlJson
9293
*
9394
* @returns Object
9495
*/
95-
const parseHtmlJson = function (htmlJson) {
96+
const filterHtmlData = function (htmlJson) {
9697
if (htmlJson && Array.isArray(htmlJson)) {
9798
var _data = htmlJson.filter((x) => x.type == 'element' && x.tagName != 'style'),
9899
styleElements = htmlJson.filter((x) => x.tagName == 'style'),
@@ -104,7 +105,7 @@ const parseHtmlJson = function (htmlJson) {
104105

105106
var elementList = _data.map((node) => {
106107
if (Array.isArray(node.children)) {
107-
let children = parseHtmlJson(node.children);
108+
let children = filterHtmlData(node.children);
108109

109110
// find text nodes and merge
110111
node.text = children.filter((x) => x.type == 'text').map((x) => {
@@ -199,6 +200,7 @@ const getSassTree = function (nodeTree, count = 0) {
199200
return '';
200201
};
201202

203+
202204
module.exports = {
203205
/**
204206
* Convert HMTL to SASS generic method
@@ -211,7 +213,8 @@ module.exports = {
211213
convertToSass: function (html, options = defaultOptions) {
212214
if (html && html.length) {
213215
const htmlJson = parse.parse(utils.cleanText(html)),
214-
sassTreeResult = getSassTree(parseHtmlJson(htmlJson));
216+
filteredHtmlData = filterHtmlData(htmlJson),
217+
sassTreeResult = getSassTree(filteredHtmlData);
215218

216219
if (options && options.formatOutput === true) {
217220
var _formatterOptions = {};

0 commit comments

Comments
 (0)