0.0.1-alpha.2
  • 编辑此页(E)
  • 报告 BUG(B)
  • 查看源码(V)
  • 单元测试(U)
  • MarkdownCompiler

    API

    查看源码
    (共 28 行)
    MarkdownCompiler 类

    表示一个 GitHub 风格的 Markdown 编译器

    继承:MarkdownIt

    构造函数

    MarkdownCompiler查看源码
    (共 23 行)
    new MarkdownCompiler

    初始化新的编译器

    参数
    参数名说明类型
    (可选)options

    附加选项

    展开子属性
    • html: boolean — Set true to enable HTML tags in source. Be careful! That's not safe! You may need external sanitizer to protect output from XSS. It's better to extend features via plugins, instead of enabling HTML.
    • xhtmlOut: boolean — Set true to add '/' when closing single tags (<br />). This is needed only for full CommonMark compatibility. In real world you will need HTML output.
    • breaks: boolean — Set true to convert \n in paragraphs into <br>.
    • langPrefix: string — CSS language class prefix for fenced blocks. Can be useful for external highlighters.
    • linkify: boolean — Set true to autoconvert URL-like text to links.
    • typographer: boolean — Set true to enable some language-neutral replacement + quotes beautification (smartquotes).
    • quotes: string | string[] — Double + single quotes replacement pairs, when typographer enabled and smartquotes on. For example, you can use '«»„“' for Russian, '„“‚‘' for German, and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
    • highlight: (str: string, lang: string) => string — Highlighter function for fenced code blocks. Highlighter function (str, lang) should return escaped HTML. It can also return empty string if the source was not changed and should be escaped externaly. If result starts with <pre... internal wrapper is skipped.
    • plugins: (string | [string | PluginWithParams, any])[]
    Options & {plugins?: (string | [string | PluginWithParams, any])[]}

    属性

    继承自 MarkdownIt 类的属性
    属性名说明类型
    inline只读

    Instance of [[ParserInline]]. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].

    ParserInline
    block只读

    Instance of [[ParserBlock]]. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].

    ParserBlock
    core只读

    Instance of [[Core]] chain executor. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].

    Core
    renderer只读

    Instance of [[Renderer]]. Use it to modify output look. Or to add rendering rules for new token types, generated by plugins.

    Example
    var md = require('markdown-it')();
    
    function myToken(tokens, idx, options, env, self) {
      //...
      return result;
    };
    
    md.renderer.rules['my_token'] = myToken
    

    See [[Renderer]] docs and source code.

    Renderer
    linkify只读

    linkify-it instance. Used by linkify rule.

    LinkifyIt
    utils只读Utils
    helpers只读
    展开子属性
    • parseLinkLabel: typeof parseLinkLabel
    • parseLinkDestination: typeof parseLinkDestination
    • parseLinkTitle: typeof parseLinkTitle
    Helpers
    options只读
    展开子属性
    • html: boolean — Set true to enable HTML tags in source. Be careful! That's not safe! You may need external sanitizer to protect output from XSS. It's better to extend features via plugins, instead of enabling HTML.
    • xhtmlOut: boolean — Set true to add '/' when closing single tags (<br />). This is needed only for full CommonMark compatibility. In real world you will need HTML output.
    • breaks: boolean — Set true to convert \n in paragraphs into <br>.
    • langPrefix: string — CSS language class prefix for fenced blocks. Can be useful for external highlighters.
    • linkify: boolean — Set true to autoconvert URL-like text to links.
    • typographer: boolean — Set true to enable some language-neutral replacement + quotes beautification (smartquotes).
    • quotes: string | string[] — Double + single quotes replacement pairs, when typographer enabled and smartquotes on. For example, you can use '«»„“' for Russian, '„“‚‘' for German, and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
    • highlight: (str: string, lang: string) => string — Highlighter function for fenced code blocks. Highlighter function (str, lang) should return escaped HTML. It can also return empty string if the source was not changed and should be escaped externaly. If result starts with <pre... internal wrapper is skipped.
    Options

    方法

    继承自 MarkdownIt 类的方法

    Link validation function. CommonMark allows too much in links. By default we disable javascript:, vbscript:, file: schemas, and almost all data:... schemas except some embedded image types.

    You can change this behaviour:

    var md = require('markdown-it')();
    // enable everything
    md.validateLink = function () { return true; }
    
    参数
    参数名说明类型
    urlstring
    返回值
    类型:boolean

    Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.

    参数
    参数名说明类型
    urlstring
    返回值
    类型:string

    MarkdownItnormalizeLinkText

    Function used to decode link url to a human-readable format`

    参数
    参数名说明类型
    urlstring
    返回值
    类型:string

    MarkdownItset

    chainable

    Set parser options (in the same format as in constructor). Probably, you will never need it, but you can change options after constructor call.

    Example
    var md = require('markdown-it')()
                .set({ html: true, breaks: true })
                .set({ typographer: true });
    

    Note: To achieve the best possible performance, don't modify a markdown-it instance options on the fly. If you need multiple configurations it's best to create multiple instances and initialize each with separate config.

    参数
    参数名说明类型
    options
    展开子属性
    • html: boolean — Set true to enable HTML tags in source. Be careful! That's not safe! You may need external sanitizer to protect output from XSS. It's better to extend features via plugins, instead of enabling HTML.
    • xhtmlOut: boolean — Set true to add '/' when closing single tags (<br />). This is needed only for full CommonMark compatibility. In real world you will need HTML output.
    • breaks: boolean — Set true to convert \n in paragraphs into <br>.
    • langPrefix: string — CSS language class prefix for fenced blocks. Can be useful for external highlighters.
    • linkify: boolean — Set true to autoconvert URL-like text to links.
    • typographer: boolean — Set true to enable some language-neutral replacement + quotes beautification (smartquotes).
    • quotes: string | string[] — Double + single quotes replacement pairs, when typographer enabled and smartquotes on. For example, you can use '«»„“' for Russian, '„“‚‘' for German, and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
    • highlight: (str: string, lang: string) => string — Highlighter function for fenced code blocks. Highlighter function (str, lang) should return escaped HTML. It can also return empty string if the source was not changed and should be escaped externaly. If result starts with <pre... internal wrapper is skipped.
    Options
    返回值
    类型:MarkdownIt

    MarkdownItconfigure

    chainable, internal

    Batch load of all options and compenent settings. This is internal method, and you probably will not need it. But if you with - see available presets and data structure here

    We strongly recommend to use presets instead of direct config loads. That will give better compatibility with next versions.

    参数
    参数名说明类型
    presetsPresetName
    返回值
    类型:MarkdownIt

    MarkdownItenable

    chainable

    Enable list or rules. It will automatically find appropriate components, containing rules with given names. If rule not found, and ignoreInvalid not set - throws exception.

    Example
    var md = require('markdown-it')()
                .enable(['sub', 'sup'])
                .disable('smartquotes');
    
    参数
    参数名说明类型
    list

    rule name or list of rule names to enable

    string | string[]
    (可选)ignoreInvalid

    set true to ignore errors when rule not found.

    boolean
    返回值
    类型:MarkdownIt

    MarkdownItdisable

    chainable

    The same as [[MarkdownIt.enable]], but turn specified rules off.

    参数
    参数名说明类型
    list

    rule name or list of rule names to disable.

    string | string[]
    (可选)ignoreInvalid

    set true to ignore errors when rule not found.

    boolean
    返回值
    类型:MarkdownIt

    MarkdownItuse

    chainable

    Load specified plugin with given params into current parser instance. It's just a sugar to call plugin(md, params) with curring.

    Example
    var iterator = require('markdown-it-for-inline');
    var md = require('markdown-it')()
                .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
                  tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
                });
    
    • 重载 2
    泛型参数
    • T = any
    参数
    参数名说明类型
    pluginPluginWithOptions<T>
    (可选)optionsT
    返回值
    类型:MarkdownIt
    参数
    参数名说明类型
    pluginPluginWithParams
    ...paramsany[]
    返回值
    类型:MarkdownIt

    MarkdownItparse

    internal

    Parse input string and returns list of block tokens (special token type "inline" will contain list of inline tokens). You should not call this method directly, until you write custom renderer (for example, to produce AST).

    env is used to pass data between "distributed" rules and return additional metadata like reference info, needed for the renderer. It also can be used to inject data in specific cases. Usually, you will be ok to pass {}, and then pass updated object to renderer.

    参数
    参数名说明类型
    src

    source string

    string
    env

    environment sandbox

    any
    返回值
    类型:Token[]

    MarkdownItrender

    Render markdown string into html. It does all magic for you :).

    env can be used to inject additional metadata ({} by default). But you will not need it with high probability. See also comment in [[MarkdownIt.parse]].

    参数
    参数名说明类型
    src

    source string

    string
    (可选)env

    environment sandbox

    any
    返回值
    类型:string

    MarkdownItparseInline

    internal

    The same as [[MarkdownIt.parse]] but skip all block rules. It returns the block tokens list with the single inline element, containing parsed inline tokens in children property. Also updates env object.

    参数
    参数名说明类型
    src

    source string

    string
    env

    environment sandbox

    any
    返回值
    类型:Token[]

    MarkdownItrenderInline

    Similar to [[MarkdownIt.render]] but for single paragraph content. Result will NOT be wrapped into <p> tags.

    参数
    参数名说明类型
    src

    source string

    string
    (可选)env

    environment sandbox

    any
    返回值
    类型:string

    查看源码
    (共 26 行)
    todoList

    MarkdownIt 插件:支持任务列表

    参数
    参数名说明类型
    mdMarkdownIt
    (可选)renderCheckBox

    默认值:(checked, context) => `<input type="checkbox"${checked ? ` checked="checked"` : ""} disabled="disabled">`;

    (checked: boolean, context: any) => string
    返回值
    类型:void

    查看源码
    (共 41 行)
    imageBlock

    MarkdownIt 插件:支持将独立的图片放到 <figure>

    参数
    参数名说明类型
    mdMarkdownIt
    返回值
    类型:void

    查看源码
    (共 47 行)
    table

    MarkdownIt 插件:支持扩展表格

    参数
    参数名说明类型
    mdMarkdownIt
    返回值
    类型:void

    查看源码
    (共 16 行)
    image

    MarkdownIt 插件:支持生成图片占位符和其它错误占位符

    参数
    参数名说明类型
    mdMarkdownIt
    (可选)render(token: Token, context: any) => any
    返回值
    类型:void

    查看源码
    (共 29 行)
    blockquote

    MarkdownIt 插件:为块级引用添加颜色样式

    参数
    参数名说明类型
    mdMarkdownIt
    (可选)markers

    默认值:{ }

    {[name: string]: {class: stringrenderIcon?: function(content: string, context: any) => string}}
    (可选)renderOpenTitle(context: any) => string
    (可选)renderCloseTitle(context: any) => string
    返回值
    类型:void

    查看源码
    (共 83 行)
    container

    MarkdownIt 插件:支持插入容器

    参数
    参数名说明类型
    mdMarkdownIt
    renderers
    展开子属性
    • renderOpenContainer: RenderRule
    • renderCloseContainer: RenderRule
    • renderOpenSeperator: RenderRule
    • renderCloseSeperator: RenderRule
    {renderOpenContainer: RenderRulerenderCloseContainer: RenderRulerenderOpenSeperator: RenderRulerenderCloseSeperator: RenderRule}
    返回值
    类型:void

    查看源码
    (共 8 行)
    code

    MarkdownIt 插件:支持代码块

    参数
    参数名说明类型
    mdMarkdownIt
    renderCode(content: string, lang: string, context: any) => string
    返回值
    类型:void

    MarkdownIt 插件:支持链接扩展

    参数
    参数名说明类型
    mdMarkdownIt
    {redirect, isEnternal, externalClass, renderExternalIcon}
    展开子属性
    • redirect: ?
    • isEnternal: ?
    • externalClass: ?
    • renderExternalIcon: ?
    {redirect?: function(url: string, context: any) => stringisEnternal?: function(url: string, context: any) => booleanexternalClass?: stringrenderExternalIcon?: function(token: Token, context: any) => string}
    返回值
    类型:void

    查看源码
    (共 22 行)
    embed

    MarkdownIt 插件:支持使用 {@...} 语法内嵌其它内容

    参数
    参数名说明类型
    mdMarkdownIt
    render(type: string, content: string, context: any) => string
    返回值
    类型:void

    查看源码
    (共 30 行)
    heading

    MarkdownIt 插件:支持为每个标题生成索引

    参数
    参数名说明类型
    mdMarkdownIt
    getAnchor(token: Token, content: string, hash: string, context: any) => string
    返回值
    类型:void

    MarkdownIt 插件:支持标题插入描点

    参数
    参数名说明类型
    mdMarkdownIt
    renderParmaLink(anchor: string, token: Token, context: any) => string
    返回值
    类型:void

    查看源码
    (共 6 行)
    html

    MarkdownIt 插件:支持转换内联 HTML

    参数
    参数名说明类型
    mdMarkdownIt
    renderHTML(content: string, context: any) => string
    返回值
    类型:void