本文整理汇总了TypeScript中markdown-it.render函数的典型用法代码示例。如果您正苦于以下问题:TypeScript render函数的具体用法?TypeScript render怎么用?TypeScript render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transform
transform(data: string): SafeHtml {
if (data) {
const md = new MarkdownIt();
md.use(markdownItAttrs);
return this.sanitizer.bypassSecurityTrustHtml(md.render(data));
} else {
return this.sanitizer.bypassSecurityTrustHtml('No Data');
}
}
示例2: authToken
router.post("/add_announce", async ctx => {
await authToken(ctx, true);
const { title, content } = ctx.request.body;
if (!title) {
return raiseApiError(400, "未填写通知标题");
}
const announce = new Announce(title, md.render(content));
await getRepository(Announce).save(announce);
await announceMail(announce, await getRepository(User).find());
ctx.body = { message: "创建成功" };
});
示例3: Announce
router.post("/announces", async ctx => {
const announce = new Announce(
ctx.request.body.title,
md.render(ctx.request.body.content)
);
await connection.getRepository(Announce).save(announce);
const users = await connection.getRepository(User).find();
// TODO: use job queues
await announceMail(announce, users);
// TODO: better appearance
ctx.response.status = 200;
ctx.response.type = "text/html";
ctx.response.body = `Succeeded.<a href="/admin">Go back</a>`;
});
示例4: parsePageMetadata
/**
* Parse the AST of a file and get metadata about it
*/
function parsePageMetadata(filePath: string, sourceContent: string): PageMetadata {
const markup = md.render(sourceContent).replace(/\n/g, '');
const fileName = path.basename(filePath, '.md');
return {
id: fileName,
name: convertToCamelCase(fileName),
title: convertToSentence(fileName),
section: path
.dirname(filePath)
.split('/') // Platform specific File separator doesn't apply
.slice(-2, -1)[0],
template: markup,
route: path
.dirname(filePath)
.split('/')
.slice(3)
.join('/'),
};
}
示例5: process
function process(
markdown_string: string,
mode: "default" | "frontmatter"
): MD2html {
let text: string;
let math: string[];
// console.log(0, JSON.stringify(markdown_string));
// console.log(1, JSON.stringify(math_escape(markdown_string)));
[text, math] = remove_math(math_escape(markdown_string));
// console.log(2, JSON.stringify(text), JSON.stringify(math));
// Process checkboxes [ ].
text = checkboxes(text);
let html: string;
let frontmatter = "";
// avoid instantiating a new markdown object for normal md processing
if (mode == "frontmatter") {
const md_frontmatter = new MarkdownIt(OPTIONS).use(
MarkdownItFrontMatter,
fm => {
frontmatter = fm;
}
);
html = md_frontmatter.render(text);
} else {
html = markdown_it.render(text);
}
// console.log(3, JSON.stringify(html));
// Substitute processed math back in.
html = replace_math(html, math);
// console.log(4, JSON.stringify(html));
html = math_unescape(html);
// console.log(5, JSON.stringify(html));
return { html, frontmatter };
}
示例6: 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-',
示例7: MarkdownIt
const md = new MarkdownIt();
md.use(MarkdownItContainer, 'spoiler', {
validate: (params: any) => params.trim().match(/^spoiler\s+(.*)$/),
render: (tokens: MarkdownIt.Token[], index: number) => {
const match = tokens[index].info.trim().match(/^spoiler\s+(.*)$/);
const onClick =
"this.parentNode.classList.toggle('_expanded');" +
"event.preventDefault();";
if (tokens[index].nesting === 1) {
return (
'<div class="markdown__spoiler">\n' +
'<div class="markdown__spoiler-title" onclick="' + onClick + '">\n' +
md.utils.escapeHtml(match && match[1] || '') + '\n' +
'</div>\n' +
'<div class="markdown__spoiler-content">\n'
);
} else {
return '</div></div>\n';
}
}
});
const src = `:::spoiler This Is Spoiler Title
Here is spoiler content.
:::`;
md.render(src);
示例8: MarkdownItRenderer
function MarkdownItRenderer(input: any) {
return rnd.render(DOMPurify.sanitize(input, { ALLOWED_TAGS: [] }))
}