本文整理汇总了TypeScript中highlight.js类的典型用法代码示例。如果您正苦于以下问题:TypeScript js类的具体用法?TypeScript js怎么用?TypeScript js使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了js类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getRenderedSourceCode
async function getRenderedSourceCode(): Promise<string> {
let printConfig = vscode.workspace.getConfiguration("print", null);
let printAndClose = printConfig.printAndClose ? " onload = \"window.print();window.close();\"" : "";
if (printConfig.renderMarkdown && commandArgs.fsPath.split('.').pop().toLowerCase() === "md") {
let markdownConfig = vscode.workspace.getConfiguration("markdown", null);
return `<!DOCTYPE html><html><head><title>${commandArgs.fsPath}</title>
<meta charset="utf-8"/>
<style>
html, body {
font-family: ${markdownConfig.preview.fontFamily};
font-size: ${markdownConfig.preview.fontSize}px;
line-height: ${markdownConfig.preview.lineHeight}em;
}
img {
max-width: 100%;
}
h1,h2,h3,h4,h5,h6 {
page-break-after:avoid;
page-break-inside:avoid;
}
</style>
${markdownConfig.styles.map((cssFilename: string) => `<link href="${cssFilename}" rel="stylesheet" />`).join("\n")}
</head>
<body${printAndClose}>${markdown_it().render(fs.readFileSync(commandArgs.fsPath).toString())}</body></html>`;
}
let x = vscode.extensions.getExtension("pdconsec.vscode-print");
if (!x) { throw new Error("Cannot resolve extension. Has the name changed? It is defined by the publisher and the extension name defined in package.json"); }
let stylePath = `${x.extensionPath}/node_modules/highlight.js/styles`;
let defaultCss = getFileText(`${stylePath}/default.css`);
let swatchCss = getFileText(`${stylePath}/${printConfig.colourScheme}.css`);
let sourceCode = await getSourceCode();
let renderedCode = "";
try {
renderedCode = hljs.highlight(sourceCode[0], sourceCode[1]).value;
}
catch (err) {
renderedCode = hljs.highlightAuto(sourceCode[1]).value;
}
var addLineNumbers = printConfig.lineNumbers === "on" || (printConfig.lineNumbers === "inherit" && vscode.window.activeTextEditor && (vscode.window.activeTextEditor.options.lineNumbers || 0) > 0);
if (addLineNumbers) {
var startLine = selection && !(selection.isEmpty || selection.isSingleLine) ? selection.start.line + 1 : 1;
renderedCode = renderedCode
.split("\n")
.map((line, i) => `<tr><td class="line-number">${startLine + i}</td><td class="line-text">${line}</td></tr>`)
.join("\n")
.replace("\n</td>", "</td>")
;
} else {
renderedCode = renderedCode
.split("\n")
.map((line, i) => `<tr><td class="line-text">${line}</td></tr>`)
.join("\n")
.replace("\n</td>", "</td>")
;
}
let editorConfig = vscode.workspace.getConfiguration("print", null);
let html = `<html><head><title>${commandArgs.fsPath}</title><style>body{margin:0;padding:0;tab-size:${editorConfig.tabSize}}\n${defaultCss}\r${swatchCss}\n${lineNumberCss.replace("{lineSpacing}", (printConfig.lineSpacing - 1).toString())}\n.hljs { max-width:100%; width:100%; font-family: Consolas, monospace; font-size: ${printConfig.fontSize}; }\n</style></head><body${printAndClose}><table class="hljs">${renderedCode}</table></body></html>`;
return html;
}
开发者ID:natkuhn,项目名称:vsc-print,代码行数:59,代码来源:extension.ts
示例2:
renderer.code = (code, language) => {
// Check whether the given language is valid for highlight.js.
const validLang = !!(language && highlight.getLanguage(language));
// Highlight only if the language is valid.
const highlighted = validLang ? highlight.highlight(language, code).value : code;
// Render the highlighted code with `hljs` class.
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
开发者ID:seattlecodercamps,项目名称:Blixen,代码行数:8,代码来源:markdown.component.ts
示例3:
renderer.code = (code: string, language: string) => {
return `<pre class="hljs lang-${language}"><code class="${language}">${
// 如果在支持的语言列表里面就用该语言渲染,否则使用默认语言渲染
hljs.getLanguage(language) ?
hljs.highlight(language, code).value :
hljs.highlightAuto(code).value
}</code></pre>`
}
开发者ID:linkFly6,项目名称:Said,代码行数:8,代码来源:html.ts
示例4: function
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (__) { }
}
return ''; // use external default escaping
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:9,代码来源:markdown-it-tests.ts
示例5: catch
highlight: (str, lang) => {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (e) {
console.error(e);
}
}
return ''; // use external default escaping
},
开发者ID:nextcloud,项目名称:appstore,代码行数:10,代码来源:Markdown.ts
示例6: catch
highlight: (str: any, lang: any) => {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (e) {
// console.info('hightlight');
// console.info(e);
}
} else {
console.info("找不到目标语言或语言对应的高亮:" + lang);
}
return ''; // use external default escaping
},
开发者ID:weiweiwitch,项目名称:third-lab,代码行数:15,代码来源:md.ts
示例7: function
highlight: function(code: string, lang: string): string {
if (lang === undefined) {
return code;
}
if (lang === 'mermaid') {
if (!loaded_mermaid) {
const script = document.createElement('script');
script.src = 'file://' + remote.app.getAppPath() + '/bower_components/mermaid/dist/mermaid.min.js';
script.onload = () => {
mermaid.init(undefined, 'div.mermaid');
};
document.head.appendChild(script);
loaded_mermaid = true;
}
return '<div class="mermaid">' + he.encode(code) + '</div>';
}
if (lang === 'katex') {
return '<div class="katex">' + katex.renderToString(code, {displayMode: true}) + '</div>';
}
try {
return highlight(lang, code).value;
} catch (e) {
console.log('Error on highlight: ' + e.message);
return code;
}
},
开发者ID:WondermSwift,项目名称:Shiba,代码行数:30,代码来源:markdown-preview.ts
示例8: attached
async attached() {
let targets = this.element.querySelectorAll('code');
for (let i = 0; i < targets.length; i += 1) {
let target = targets[i];
hljs.highlightBlock(target);
}
}
开发者ID:adamfur,项目名称:helix,代码行数:8,代码来源:highlight.ts
示例9:
export const codeToHtml = (code: string, { language = null, interpretHints = true } = {}) => {
if (language) return `<code>${highlight(language, code).value}</code>`;
if (interpretHints) {
const langRegex = /^([\w-.]+):\s/g;
const match = langRegex.exec(code);
if (match && listLanguages().includes(match[1])) {
const restOfCode = code.substring(langRegex.lastIndex);
return `<code>${highlight(match[1], restOfCode).value}</code>`;
}
}
return `<code>${highlightAuto(code).value}</code>`;
};
开发者ID:luketurner,项目名称:scripsi,代码行数:14,代码来源:code.ts
注:本文中的highlight.js类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论