MarkdownCompiler
API
MarkdownCompiler 类
表示一个 GitHub 风格的 Markdown 编译器
MarkdownIt构造函数
new MarkdownCompiler
初始化新的编译器
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
(可选)options | 附加选项 展开子属性
  |  | 
属性
继承自 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]].  |  | 
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]].  |  | 
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]].  |  | 
renderer只读 | Instance of [[Renderer]]. Use it to modify output look. Or to add rendering rules for new token types, generated by plugins. ExampleSee [[Renderer]] docs and source code.  |  | 
linkify只读 | linkify-it instance. Used by linkify rule.  |  | 
utils只读 |  | |
helpers只读 | 展开子属性
  |  | 
options只读 | 展开子属性
  |  | 
方法
继承自 MarkdownIt 类的方法
validateLink
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; }
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
url | string | 
返回值
booleannormalizeLink
Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
url | string | 
返回值
stringnormalizeLinkText
Function used to decode link url to a human-readable format`
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
url | string | 
返回值
stringset
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 | 展开子属性
  |  | 
返回值
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.
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
presets |  | 
返回值
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   | boolean | 
返回值
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   | boolean | 
返回值
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');
            });
- 重载 1
 - 重载 2
 
泛型参数
T=any
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
plugin |  | |
(可选)options | T | 
返回值
MarkdownIt参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
plugin |  | |
...params | any[] | 
返回值
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[]render
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 | 
返回值
stringparseInline
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[]renderInline
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 | 
返回值
stringtodoList
MarkdownIt 插件:支持任务列表
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
(可选)renderCheckBox | 默认值:  | (checked: boolean, context: any) => string | 
返回值
voidimageBlock
MarkdownIt 插件:支持将独立的图片放到 <figure>
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | 
返回值
voidtable
MarkdownIt 插件:支持扩展表格
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | 
返回值
voidimage
MarkdownIt 插件:支持生成图片占位符和其它错误占位符
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
(可选)render | (token:  | 
返回值
voidblockquote
MarkdownIt 插件:为块级引用添加颜色样式
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
(可选)markers | 默认值:  | {[name: string]: {class: stringrenderIcon?: function(content: string, context: any) => string}} | 
(可选)renderOpenTitle | (context: any) => string | |
(可选)renderCloseTitle | (context: any) => string | 
返回值
voidcontainer
MarkdownIt 插件:支持插入容器
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
renderers | 展开子属性
  | {renderOpenContainer:  | 
返回值
voidcode
MarkdownIt 插件:支持代码块
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
renderCode | (content: string, lang: string, context: any) => string | 
返回值
voidlink
MarkdownIt 插件:支持链接扩展
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
{redirect, isEnternal, externalClass, renderExternalIcon} | 展开子属性
  | {redirect?: function(url: string, context: any) => stringisEnternal?: function(url: string, context: any) => booleanexternalClass?: stringrenderExternalIcon?: function(token:  | 
返回值
voidembed
MarkdownIt 插件:支持使用 {@...} 语法内嵌其它内容
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
render | (type: string, content: string, context: any) => string | 
返回值
voidheading
MarkdownIt 插件:支持为每个标题生成索引
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
getAnchor | (token:  | 
返回值
voidparmalink
MarkdownIt 插件:支持标题插入描点
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
renderParmaLink | (anchor: string, token:  | 
返回值
voidhtml
MarkdownIt 插件:支持转换内联 HTML
参数
| 参数名 | 说明 | 类型 | 
|---|---|---|
md |  | |
renderHTML | (content: string, context: any) => string | 
返回值
void