Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inlineTokenRules['fence'] = function(token, env) {
const style = getStyle(token, {fontFamily: 'Courier New'});
startStyle(style, env);
const language = token.info ? token.info.trim() : undefined;
if(language) {
const htmlTokens = low.highlight(language, token.content);
for(let token of htmlTokens.value) {
processHtmlToken(token, env);
}
} else {
// For code blocks, replace line feeds with vertical tabs to keep
// the block as a single paragraph. This avoid the extra vertical
// space that appears between paragraphs
env.text.rawText += token.content.replace(/\n/g, '\u000b');
}
env.text.rawText += '\n';
endStyle(env);
};
keywords: {
keyword:
'forall all exists exist only m M i e 1 2 3 4 5 6 7 8 9 0 - + * / \ % ! . , ; : | lim limsup liminf infinity not'
},
contains: [
{
className: 'variable',
begin: '(', end: ')'
},
]
};
}
registerLanguage('math', highlighter);
console.log(highlight('typescript',
`class CPP {
private year: number;
public constructor(private version: string) {
this.year = Number(version.match(/.+\d+$/));
}
public version(): string {
return this.version;
}
}
`
));
console.info(highlightAuto(
`class CPP {
private year: number;
visit(ast, 'code', node => {
if (!node.data) {
node.data = {};
}
const lang = node.lang;
const highlighted = lang
? low.highlight(aliases[lang] || lang, node.value).value
: low.highlightAuto(node.value).value;
node.data.hChildren = highlighted;
node.data.hProperties = {
className: ['hljs', lang && `language-${lang}`],
};
});
}
function highlight(code: string): string {
const codeMap = lowlight.highlight('clojure', code)
return walkCodeMap("", codeMap)
}
function highlightSyntax(content: string, language: string, context: Context): void {
const highlightResult = low.highlight(language, content);
for (let node of highlightResult.value) {
processHastNode(node, context);
}
}
function exampleHtml (example) {
if (!example) return []
let highlighted = lowlight.highlight('js', example.description, {
prefix: 'code-block_'
})
let pre = tag('pre', [
tag('code', highlighted.value)
])
return [pre]
}
(include && !include.includes(lang)) ||
(exclude && exclude.includes(lang))
) {
return
}
if (!data) {
data = {}
node.data = data
}
if (!data.hProperties) {
data.hProperties = {}
}
data.hChildren = low.highlight(lang, node.value, {prefix}).value
data.hProperties.className = [
'hljs',
...(data.hProperties.className || []),
'language-' + lang
]
}
}