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