本文整理汇总了TypeScript中markdown-it.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript markdown-it.default方法的具体用法?TypeScript markdown-it.default怎么用?TypeScript markdown-it.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markdown-it
的用法示例。
在下文中一共展示了markdown-it.default方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: renderMd
export function renderMd(html: string): string {
const md = markdownit({
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
},
});
return noReferrerLinks(md.render(html));
}
示例3: MarkdownIt
import * as MarkdownIt from "markdown-it";
{
const md = new MarkdownIt();
var result = md.render('# markdown-it rulezz!');
}
{
var md = MarkdownIt();
var result = md.render('# markdown-it rulezz!');
var result = md.renderInline('__markdown-it__ rulezz!');
}
{
var md = MarkdownIt('commonmark');
}
{
var md = MarkdownIt({
html: true,
linkify: true,
typographer: true
});
}
{
var md = MarkdownIt({
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
示例4: highlight
import * as MarkdownIt from 'markdown-it';
import { addLanguage, highlight, getLanguage } from 'illuminate-js';
import { jsx, bash, tsx } from 'illuminate-js/lib/languages';
import * as _ from 'lodash';
import { parse, ComponentDoc, PropItem } from './tsReactDocsParser';
addLanguage('js', jsx);
addLanguage('ts', tsx);
addLanguage('bash', bash);
const md = MarkdownIt({
html: true,
highlight(str: string, lang: string) {
if (lang && getLanguage(lang)) {
return highlight(str, lang);
}
return str;
}
});
export type ComponentDocMap = Record<string, ComponentDoc>;
export function propDFS(data: ComponentDocMap, borrows: string, name: string): Partial<PropItem> {
const arr = borrows.split(',');
const n = arr.length;
for (let i = 0; i < n; i++) {
const borrow = arr[i];
const comp = data[borrow];
示例5: markdown_it
transform(value: string): any {
return markdown_it().render(value);
}
示例6: constructor
constructor(private sanitizer: DomSanitizationService) {
this.markdownIt = markdown_it();
this.markdownIt.use(markdownitEmoji);
}