Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(tempPath, "utf8", function(err, data) {
if (err) {
return;
}
// Mark the output as being from this plugin.
console.log("*** HTMLPrettify output ***");
if (isCSS(filePath, data)) {
console.log(css_beautify(data, options["css"]));
}
else if (isHTML(filePath, data)) {
console.log(html_beautify(data, options["html"]));
}
else if (isJS(filePath, data)) {
console.log(js_beautify(data, options["js"]));
}
});
// Fail silently if the resource is not available
return resolve({
url: url,
beautified: beautified,
});
}
if (/javascript/.test(type)) {
beautified = Prism.highlight(beautifyJs(
body.substr(0, CODE_CHARACTER_LIMIT + 160), beautifyOptions)
.substr(0, CODE_CHARACTER_LIMIT), Prism.languages.javascript);
} else if (/text\/html/.test(type)) {
beautified = Prism.highlight(beautifyHtml(
body.substr(0, CODE_CHARACTER_LIMIT + 160), beautifyOptions)
.substr(0, CODE_CHARACTER_LIMIT), Prism.languages.markup);
} else if (/text\/css/.test(type)) {
beautified = Prism.highlight(beautifyCss(
body.substr(0, CODE_CHARACTER_LIMIT + 160), beautifyOptions)
.substr(0, CODE_CHARACTER_LIMIT), Prism.languages.css);
}
return resolve({
url: url,
beautified: beautified,
});
});
}));
if (event.ctrlKey && event.code === "KeyS") $(
"[data-key='Ctrl+S']").click();
if (event.ctrlKey && event.code === "KeyB") {
let currentTab = editors[$('tab[active]').attr("id")];
let settings = {
indent_size: 1,
indent_char: currentTab.getSession().getTabString(),
indent_with_tabs: (currentTab.getSession().getTabString() === "\t"),
wrap_line_length: currentTab.getSession().getWrapLimit()
};
let tabText = $(".nav-link[to=" + $('tab[active]').attr(
"id") + "] name").text();
let btext;
if (tabText.endsWith(".js") || tabText.endsWith(".json")) btext =
js_beautify(currentTab.getValue(), settings);
else if (tabText.endsWith(".css")) btext = css_beautify(currentTab.getValue(),
settings);
else if (tabText.endsWith(".html")) btext = html_beautify(currentTab.getValue(),
settings);
else return;
editors[$(`tab[active]`).attr("id")].setValue(btext);
}
});
formatCode() {
return false;
const currentLine = code.getSelectionRange().start.row
const mode = code.getSession().getMode().$id.split('/').pop()
let val = code.session.getValue()
if (mode === 'javascript') {
code.session.setValue(js_beautify(val, data.format))
code.gotoLine(currentLine + 1, Infinity)
} else if (mode === 'html') {
code.session.setValue(html(val, data.format))
code.gotoLine(currentLine + 1, Infinity)
} else if (mode === 'css') {
code.session.setValue(css(val, data.format))
code.gotoLine(currentLine + 1, Infinity)
}
}
applyRegex(regex, files) {
for (let filename in regex) {
if (files[filename]) {
if (/.js$/.test(filename)) {
files[filename] = BeautifyJs(files[filename], { "break_chained_methods": true });
}
else if (/.css$/.test(filename)) {
files[filename] = BeautifyCss(files[filename]);
}
for (let i in regex[filename]) {
files[filename] = files[filename].replace(new RegExp(regex[filename][i][0], 'g'), regex[filename][i][1]);
}
}
}
}
beautyCss(text) {
let scoped = /]*\s+scoped/.test(text) ? ' scoped' : '';
let lang = this.getLang(text);
let str = text;
text = text.replace(/]*>([\w\W]*)<\/style>/, '$1');
if (text.trim()) {
let tempConf = Object.assign({}, this.jsBeautifyConf, this.jsBeautifyConf.css);
str = beautify.css(text, tempConf);
return `\n${str}\n`;
} else {
return str;
}
},
beautyJs(text) {
case 'application/xml':
const trimContent = this.trim(content)
if (trimContent.indexOf('{') === 0 && trimContent.lastIndexOf('}') === trimContent.length - 1) {
content = BeautifyJs(content)
} else {
content = BeautifyHtml(content)
}
break
case 'text/javascript':
case 'application/json':
case 'application/javascript':
case 'application/x-javascript':
content = BeautifyJs(content)
break
case 'text/css':
content = BeautifyCss(content)
break
}
return content
},
trim (str) {
const CSS = props => {
const css = sheet.css
return (
CSS for this page
<code>{css.length} bytes</code>
<pre>
)
}
</pre>
getCss() {
let CSS = ''
this.imports.forEach(({ css }) => CSS = CSS + css)
return beautify.css(`
${CSS}
${getEditorCss()}
`)
}