Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
highlight: (str, lang) => {
require('highlight.js/styles/monokai-sublime.css')
const hljs = require('highlight.js')
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value
} catch (__) {}
}
try {
return hljs.highlightAuto(str).value
} catch (__) {}
return '' // use external default escaping
}
})
highlight: (str, lang) => {
require('highlight.js/styles/github-gist.css')
const hljs = require('highlight.js')
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value
} catch (__) {}
}
try {
return hljs.highlightAuto(str).value
} catch (__) {}
return '' // use external default escaping
}
})
highlight: (code, lang) => {
code = code.trim()
const hljs = require("highlight.js")
// language is recognized by highlight.js
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(lang, code).value
}
// ...or fallback to auto
return hljs.highlightAuto(code).value
},
})
componentUpdated: function componentUpdated(el, binding) {
// after an update, re-fill the content and then highlight
const targets = el.querySelectorAll('code');
for (let i = 0; i < targets.length; i += 1) {
const target = targets[i];
if (binding.value) {
target.textContent = binding.value;
hljs.highlightBlock(target);
}
}
}
});
module.exports = function(options) {
highlight.configure(options);
let normalizedOptions = Object.assign({}, defaults, options);
let {selector} = normalizedOptions;
return function highlightContent(root, data, metalsmith, done) {
Array.from(root.querySelectorAll(selector)).forEach(node => {
highlight.highlightBlock(node);
// Tag the parent node as well for style adjustments
if (node.parentNode && node.parentNode.classList) {
node.parentNode.classList.add('lang-highlight');
}
});
done();
};
};
ngAfterViewInit(): void {
let codeEl = this.elementRef.nativeElement.querySelector('code');
hljs.highlightBlock(codeEl);
}
module.exports = function(options = {}) {
highlightjs.configure(options);
/**
* @param {Object} files files
* @param {Metalsmith} metalsmith metalsmith
* @param {Function} done done
* @returns {void}
*/
return function(files, metalsmith, done) {
let file, data;
for (file in files) {
if (HTML_FILENAME_REGEXP.test(file)) {
data = files[file];
data.contents = Buffer.from(highlightFile(data.contents.toString()));
}
}
highlight: function (code, lang) {
var res;
res = void 0;
if (!lang) {
return code;
}
switch (lang) {
case "js":
lang = "javascript";
}
try {
return res = hljs.highlight(lang, code).value;
} finally {
return res || code;
}
}
};
highlight: function (code, lang) {
var res = void 0;
if (!lang) {
return code;
}
switch (lang) {
case "js":
lang = "javascript";
}
try {
return res = hljs.highlight(lang, code).value;
} finally {
return res || code;
}
}
}, (opts.marked || {})));
highlight : function(code, lang) {
if (lang == 'js') lang = 'javascript';
if (lang && hljs.LANGUAGES[lang]) {
return hljs.highlight(lang, code).value;
}
return hljs.highlightAuto(code).value;
}
});