本文整理匯總了TypeScript中highlight.js.default.highlight方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.default.highlight方法的具體用法?TypeScript js.default.highlight怎麽用?TypeScript js.default.highlight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類highlight.js.default
的用法示例。
在下文中一共展示了js.default.highlight方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
highlight: (code: string, language: string): string => {
if (language) {
// highlight.js expects "typescript" written out, while Github supports "ts".
let lang = language.toLowerCase() === 'ts' ? 'typescript' : language;
return hljs.highlight(lang, code).value;
}
return code;
}
示例2: function
highlight: function(str: string, lang: string) {
if (lang && HighlightJS.getLanguage(lang)) {
try {
return HighlightJS.highlight(lang, str).value
} catch (__) { }
}
return ''; // use external default escaping
}
示例3: function
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (__) {
}
}
return ''; // use external default escaping
},
示例4:
renderer.code = (code, language) => {
// Check whether the given language is valid for highlight.js.
const validLang = !!(language && hljs.getLanguage(language));
language = validLang ? language : 'html'; // Default to html
// Highlight only if the language is valid.
const highlighted = hljs.highlight(language, code).value;
// Render the highlighted code with `hljs` class.
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
示例5: function
var hlight = function(code:string,language:string) {
var hljs = require('highlight.js');
var html;
if (typeof language === "undefined") {
html = (hljs.highlight(language, code)).value;
}
else {
html = (hljs.highlightAuto(code)).value;
};
return html2console('<pre class="hljs">' + html + '</pre>');
};
示例6: highlightFn
options.renderer.code = function highlightFn(code, language) {
const validLang = !!(language && hljs.getLanguage(language));
const highlighted = validLang ? hljs.highlight(language, code).value : code;
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
示例7:
marked.setOptions({ highlight: (code, lang) => {
if (lang == null) lang = "typescript";
return hljs.highlight(lang, code).value;
}