本文整理匯總了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;
}