本文整理汇总了TypeScript中markdown-it.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: markdownIt
import url from "url";
import markdownIt from "markdown-it";
import mdUrl from "./markdown-url-to-html";
const markdown = markdownIt({
html: true,
linkify: true,
typographer: true
}).use(transformLocalMdLinksToHTML);
function transformLocalMdLinksToHTML(md: any) {
const defaultLinkOpenRender =
md.renderer.rules.link_open ||
function(tokens: any, idx: any, options: any, env: any, self: any) {
return self.renderToken(tokens, idx, options);
};
md.renderer.rules.link_open = function(
tokens: any,
idx: any,
options: any,
env: any,
self: any
) {
const a = tokens[idx];
const href = a.attrGet("href");
if (href) {
a.attrSet("href", localMarkdownLinkToHtmlLink(href));
}
return defaultLinkOpenRender(tokens, idx, options, env, self);
};
}
示例2: constructor
constructor(options?: PluginOptions) {
this._markdownProcessor = markdownIt(options);
if (!!options && Array.isArray(options.plugins)) {
options.plugins.map(this.installPlugin.bind(this));
}
}
示例3: pageModuleTemplate
module.exports = function bookLoader(content: string): string {
this.cacheable(true);
const query = loaderUtils.parseQuery(this.query);
const {toc} = query;
const {attributes, body} = fm<{[key: string]: any}>(content);
if (query.markdown === false || attributes.markdown === false) {
content = jsTemplate(body);
} else {
const {bookLoaderOptions = {}} = this;
const md = markdownIt({
html: true,
...bookLoaderOptions.markdownOptions,
}).use(markdownJsTemplate);
if (bookLoaderOptions.markdownPlugins) {
bookLoaderOptions.markdownPlugins.forEach(md.use.bind(md));
}
content = md.render(body);
}
const context = query.context || this.options.context;
const url = attributes.hasOwnProperty('url')
? attributes.url
: loaderUtils.interpolateName(this, query.name || '[path][name].html', {
context,
content: content,
regExp: query.regExp,
});
const template = attributes.hasOwnProperty('template')
? attributes.template
: query.template;
const emit = !![attributes.emit, query.emit, url].find(
(o) => typeof o !== 'undefined',
);
return pageModuleTemplate({
url,
template,
toc,
attributes,
emit,
filename: path.relative(context, this.resourcePath),
renderFunctionBody: content,
});
};
示例4: generateGravatar
declare const md5: any;
declare const saveAs: any;
declare const componentHandler: MDLHandler;
/**
* Generate gravatar url from email
*/
export function generateGravatar(email: string) {
return `https://gravatar.lug.ustc.edu.cn/avatar/${md5(email)}?d=404&r=g`;
}
const md = require("markdown-it");
const mdc = md({
linkify: true,
typographer: false,
html: false,
breaks: true,
});
mdc.renderer.rules.paragraph_open = (tokens: any[], idx: number, options: any, env: any, self: any) => {
const token = tokens[idx];
if(token.level === 0) return `<div class="mdl-card__supporting-text">`;
else return self.renderToken(tokens, idx, options);
};
mdc.renderer.rules.paragraph_close = (tokens: any, idx: any, options: any, env: any, self: any) => {
const token = tokens[idx];
if(token.level === 0) return "</div>";
else return self.renderToken(tokens, idx, options);
};
示例5: createHtml
function createHtml(str, options = {}) {
return cheerio.load(markdownIt(options).render(str));
}
示例6: createMd
function createMd(options?) {
return markdownIt(options).use(markdownJsTemplate);
}