本文整理汇总了TypeScript中showdown.Converter类的典型用法代码示例。如果您正苦于以下问题:TypeScript Converter类的具体用法?TypeScript Converter怎么用?TypeScript Converter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Converter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
const upload = async (ctx) => {
try {
const { path, originalname } = ctx.req.file;
let name = originalname.split('.');
let blog = await Blog.repositry.findOne({ url: name[0] });
if (blog) {
throw { message: "Blog Existed" };
}
let data = await getFileData(path);
let markdown = data.toString()
let converter = new showdown.Converter();
converter.setOption('noHeaderId', 'true');
await fs.unlinkSync(path);
ctx.body = {
success: true,
data: {
name: name[0],
html: converter.makeHtml(markdown),
markdown: markdown
}
}
} catch (error) {
ctx.status = 500;
ctx.body = error.message;
}
}
示例2: genVars
router.get('/*/*', async ctx => {
const lang = ctx.params[0];
const doc = ctx.params[1];
showdown.extension('urlExtension', () => ({
type: 'output',
regex: /%URL%/g,
replace: config.url
}));
showdown.extension('apiUrlExtension', () => ({
type: 'output',
regex: /%API_URL%/g,
replace: config.api_url
}));
const conv = new showdown.Converter({
tables: true,
extensions: ['urlExtension', 'apiUrlExtension', 'highlightjs']
});
const md = fs.readFileSync(`${__dirname}/../../../src/docs/${doc}.${lang}.md`, 'utf8');
await ctx.render('../../../../src/docs/article', Object.assign({
id: doc,
html: conv.makeHtml(md),
title: md.match(/^# (.+?)\r?\n/)[1],
src: `https://github.com/syuilo/misskey/tree/master/src/docs/${doc}.${lang}.md`
}, await genVars(lang)));
});
示例3: getMarkdownConverter
static getMarkdownConverter(): Converter {
let c = new Converter();
c.setOption('openLinksInNewWindow', 'true');
c.setOption('simplifiedAutoLink', 'true');
c.setOption('excludeTrailingPunctuationFromURLs ', 'true');
return c;
}
示例4: getHtml
export function getHtml(markdownFilePath: string): string {
var showdown = require('showdown'),
converter = new showdown.Converter()
//let markdownFilePath = Path.join(IntoCpsApp.getInstance().getActiveProject().getRootFilePath(), "Readme.md");
if (fs.existsSync(markdownFilePath)) {
var text = "" + fs.readFileSync(markdownFilePath);
text = text.split("](").join("](" + IntoCpsApp.getInstance().getActiveProject().getRootFilePath() + "/")
let html = converter.makeHtml(text);
return html;
}
return null;
}
示例5: transform
transform(markup: string) {
let converter = new showdown.Converter();
return converter.makeHtml(markup);
}
示例6: async
const getPost = async (posts: any[], slug: string): Promise<any> => {
const postData = posts.find((post) => post.slug === slug);
if (!postData) {
return {
error: true,
};
}
try {
const articlePath: string = path.resolve(POSTS_DIR, postData.path, "article.md");
const entry: string = await fs.readFile(articlePath, "utf-8");
return {
...postData,
entry: converter.makeHtml(entry),
};
} catch (error) {
if (postData.url) {
return {
redirect: postData.url,
};
}
}
};
示例7:
textChanged(newValue: string) {
if (newValue) {
this.element.innerHTML = this.converter.makeHtml(newValue);
PR.prettyPrint();
} else {
this.element.innerHTML = "";
}
}
示例8: async
const getPost = async (postPath: string): Promise<any> => {
const postDataPath: string = path.resolve(POSTS_DIR, postPath, "data.json");
try {
const postData: string = await fs.readFile(postDataPath, "utf-8");
const post = JSON.parse(postData);
return {
...post,
abstract: converter.makeHtml(post.abstract),
slug: postPath.split("-").splice(1).join("-"),
path: postPath,
};
} catch (error) {
console.error(error);
}
return null;
};
示例9: convertAndSanitizeMarkdown
export function convertAndSanitizeMarkdown(markdown: string) {
const html = converter.makeHtml(markdown);
const sanitized = DOMPurify.sanitize(html);
return sanitized;
}