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. Example
See [[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 |
返回值
boolean
normalizeLink
Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.
参数
参数名 | 说明 | 类型 |
---|---|---|
url | string |
返回值
string
normalizeLinkText
Function used to decode link url to a human-readable format`
参数
参数名 | 说明 | 类型 |
---|---|---|
url | string |
返回值
string
set
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 | 展开子属性
|
|
返回值
MarkdownIt
configure
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 |
|
返回值
MarkdownIt
enable
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 |
返回值
MarkdownIt
disable
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 |
返回值
MarkdownIt
use
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[] |
返回值
MarkdownIt
parse
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 |
返回值
string
parseInline
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 |
返回值
string
todoList
MarkdownIt 插件:支持任务列表
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
(可选)renderCheckBox | 默认值: | (checked: boolean, context: any) => string |
返回值
void
imageBlock
MarkdownIt 插件:支持将独立的图片放到 <figure>
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
|
返回值
void
table
MarkdownIt 插件:支持扩展表格
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
|
返回值
void
image
MarkdownIt 插件:支持生成图片占位符和其它错误占位符
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
(可选)render | (token: |
返回值
void
blockquote
MarkdownIt 插件:为块级引用添加颜色样式
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
(可选)markers | 默认值: | {[name: string]: {class: stringrenderIcon?: function(content: string, context: any) => string}} |
(可选)renderOpenTitle | (context: any) => string | |
(可选)renderCloseTitle | (context: any) => string |
返回值
void
container
MarkdownIt 插件:支持插入容器
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
renderers | 展开子属性
| {renderOpenContainer: |
返回值
void
code
MarkdownIt 插件:支持代码块
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
renderCode | (content: string, lang: string, context: any) => string |
返回值
void
link
MarkdownIt 插件:支持链接扩展
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
{redirect, isEnternal, externalClass, renderExternalIcon} | 展开子属性
| {redirect?: function(url: string, context: any) => stringisEnternal?: function(url: string, context: any) => booleanexternalClass?: stringrenderExternalIcon?: function(token: |
返回值
void
embed
MarkdownIt 插件:支持使用 {@...}
语法内嵌其它内容
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
render | (type: string, content: string, context: any) => string |
返回值
void
heading
MarkdownIt 插件:支持为每个标题生成索引
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
getAnchor | (token: |
返回值
void
parmalink
MarkdownIt 插件:支持标题插入描点
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
renderParmaLink | (anchor: string, token: |
返回值
void
html
MarkdownIt 插件:支持转换内联 HTML
参数
参数名 | 说明 | 类型 |
---|---|---|
md |
| |
renderHTML | (content: string, context: any) => string |
返回值
void