Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated HTML for Js support #12

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions core-plugins/html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const chalk = require('chalk');


module.exports = (text) => (
new Promise((resolve, reject) => {

Expand All @@ -14,13 +15,43 @@ module.exports = (text) => (
let first = false
let escaped = false
let doubleQuotesUsed = false;
let boom = ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning on boom ?

let isJs = false


for (let c of text) {

if(!isJs) {
boom += c;
if(boom === '<script>') {
isJs = true
boom = ''
} else if(!(boom === '<' || boom === '<s' || boom === '<sc' || boom === '<scr' || boom === '<scri' || boom === '<scrip' || boom === '<script')){
boom = ''
}

} else {
boom += c
if(boom === '</script>') {
buildML = buildML.slice(0, -8);
buildML += chalk.magenta('<') + chalk.red('/script') + chalk.magenta('>')
isJs = false
boom = ''
continue
} else if(!(boom === '<' || boom === '</' || boom === '</s' || boom === '</sc' || boom === '</scr' || boom === '</scri' || boom === '</scrip' || boom === '</script')){
boom = ''
}
buildML += c;
continue
}



if (c === "<") {
tagStart = true
first = true
} else if (c === ">") {

if(buildWord)
{
buildTag += chalk.green(buildWord)
Expand Down Expand Up @@ -49,7 +80,7 @@ module.exports = (text) => (
} else {
doubleQuotesUsed = false
}
}
}
else {
buildWord += c
if (escaped) {
Expand All @@ -70,11 +101,11 @@ module.exports = (text) => (
buildWord += c
if (escaped) {
escaped = false
}
}
else {
escaped = true
}
}
}
else {
buildTag += c
}
Expand Down Expand Up @@ -108,7 +139,7 @@ module.exports = (text) => (
} else if (c === "!") {
if(first){
buildTag += c
commentStart = true
commentStart = true
} else {
buildWord += c
}
Expand All @@ -132,4 +163,4 @@ module.exports = (text) => (

resolve(buildML)
})
);
);