• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript markdown-it类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中markdown-it的典型用法代码示例。如果您正苦于以下问题:TypeScript markdown-it类的具体用法?TypeScript markdown-it怎么用?TypeScript markdown-it使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了markdown-it类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: 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-',
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:markdown-it-tests.ts


示例2: highlight

import * as MarkdownIt from 'markdown-it';
import { addLanguage, highlight, getLanguage } from 'illuminate-js';
import { jsx, bash, tsx } from 'illuminate-js/lib/languages';
import * as _ from 'lodash';

import { parse, ComponentDoc, PropItem } from './tsReactDocsParser';

addLanguage('js', jsx);
addLanguage('ts', tsx);
addLanguage('bash', bash);

const md = MarkdownIt({
    html: true,
    highlight(str: string, lang: string) {
        if (lang && getLanguage(lang)) {
            return highlight(str, lang);
        }

        return str;
    }
});

export type ComponentDocMap = Record<string, ComponentDoc>;

export function propDFS(data: ComponentDocMap, borrows: string, name: string): Partial<PropItem> {
    const arr = borrows.split(',');
    const n = arr.length;

    for (let i = 0; i < n; i++) {
        const borrow = arr[i];
        const comp = data[borrow];
开发者ID:vkbansal,项目名称:scripts,代码行数:31,代码来源:react-docs.ts


示例3: getRenderedSourceCode

async function getRenderedSourceCode(): Promise<string> {
  let printConfig = vscode.workspace.getConfiguration("print", null);
  let printAndClose = printConfig.printAndClose ? " onload = \"window.print();window.close();\"" : "";
  if (printConfig.renderMarkdown && commandArgs.fsPath.split('.').pop().toLowerCase() === "md") {
    let markdownConfig = vscode.workspace.getConfiguration("markdown", null);
    return `<!DOCTYPE html><html><head><title>${commandArgs.fsPath}</title>
    <meta charset="utf-8"/>
    <style>
    html, body {
      font-family: ${markdownConfig.preview.fontFamily};
      font-size: ${markdownConfig.preview.fontSize}px;
      line-height: ${markdownConfig.preview.lineHeight}em;
    }
    img {
      max-width: 100%;
    }
    h1,h2,h3,h4,h5,h6 {
      page-break-after:avoid;
      page-break-inside:avoid;
    }
    </style>
    ${markdownConfig.styles.map((cssFilename: string) => `<link href="${cssFilename}" rel="stylesheet" />`).join("\n")}
    </head>
    <body${printAndClose}>${markdown_it().render(fs.readFileSync(commandArgs.fsPath).toString())}</body></html>`;
  }
  let x = vscode.extensions.getExtension("pdconsec.vscode-print");
  if (!x) { throw new Error("Cannot resolve extension. Has the name changed? It is defined by the publisher and the extension name defined in package.json"); }
  let stylePath = `${x.extensionPath}/node_modules/highlight.js/styles`;
  let defaultCss = getFileText(`${stylePath}/default.css`);
  let swatchCss = getFileText(`${stylePath}/${printConfig.colourScheme}.css`);
  let sourceCode = await getSourceCode();
  let renderedCode = "";
  try {
    renderedCode = hljs.highlight(sourceCode[0], sourceCode[1]).value;
  }
  catch (err) {
    renderedCode = hljs.highlightAuto(sourceCode[1]).value;
  }
  var addLineNumbers = printConfig.lineNumbers === "on" || (printConfig.lineNumbers === "inherit" && vscode.window.activeTextEditor && (vscode.window.activeTextEditor.options.lineNumbers || 0) > 0);
  if (addLineNumbers) {
    var startLine = selection && !(selection.isEmpty || selection.isSingleLine) ? selection.start.line + 1 : 1;
    renderedCode = renderedCode
      .split("\n")
      .map((line, i) => `<tr><td class="line-number">${startLine + i}</td><td class="line-text">${line}</td></tr>`)
      .join("\n")
      .replace("\n</td>", "</td>")
      ;
  } else {
    renderedCode = renderedCode
      .split("\n")
      .map((line, i) => `<tr><td class="line-text">${line}</td></tr>`)
      .join("\n")
      .replace("\n</td>", "</td>")
      ;
  }
  let editorConfig = vscode.workspace.getConfiguration("print", null);
  let html = `<html><head><title>${commandArgs.fsPath}</title><style>body{margin:0;padding:0;tab-size:${editorConfig.tabSize}}\n${defaultCss}\r${swatchCss}\n${lineNumberCss.replace("{lineSpacing}", (printConfig.lineSpacing - 1).toString())}\n.hljs { max-width:100%; width:100%; font-family: Consolas, monospace; font-size: ${printConfig.fontSize}; }\n</style></head><body${printAndClose}><table class="hljs">${renderedCode}</table></body></html>`;
  return html;
}
开发者ID:natkuhn,项目名称:vsc-print,代码行数:59,代码来源:extension.ts


示例4: renderMd

export function renderMd(html: string): string {
    const md = markdownit({
        highlight: (str, lang) => {
            if (lang && hljs.getLanguage(lang)) {
                try {
                    return hljs.highlight(lang, str).value;
                } catch (e) {
                    console.error(e);
                }
            }
            return ''; // use external default escaping
        },
    });
    return noReferrerLinks(md.render(html));
}
开发者ID:nextcloud,项目名称:appstore,代码行数:15,代码来源:Markdown.ts


示例5: markdown_it

 transform(value: string): any {
   return markdown_it().render(value);
 }
开发者ID:KonarKorona,项目名称:flowchat,代码行数:3,代码来源:markdown.pipe.ts


示例6: constructor

 constructor(private sanitizer: DomSanitizationService) {
   this.markdownIt = markdown_it();
   this.markdownIt.use(markdownitEmoji);
 }
开发者ID:diazjordi,项目名称:flowchat,代码行数:4,代码来源:markdown.pipe.ts



注:本文中的markdown-it类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript marked类代码示例发布时间:2022-05-28
下一篇:
TypeScript lunr类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap