本文整理匯總了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: [] }))
}