yamd
yamd: {
parser: { ... },
renderer: { ... },
highlighter: { ... },
ast2nt: Function,
render: Function,
highlight: Function,
cascade: Function,
set: Function,
addCodeMirrorMode: Function
}
parser
파서. 개별 문서 참조.
renderer
렌더러. 개별 문서 참조.
highlighter
구문 강조를 한다. 개별 문서 참조.
ast2nt(ast, options)
AST로부터 노드의 트리를 만든다. yamd.renderer.ast2nt(ast, options)
와 같은데 yamd
의 글로벌 옵션이 적용되며 options
는 글로벌 옵션을 cascade 한다.
Parameters
Returns
Element
노드 트리.
render(input, options)
입력으로부터 HTML을 렌더링 한다.
Parameters
input: string
: 입력 문자열.options
: 렌더링 옵션. 렌더링 옵션을 참조하라.
Returns
string
렌더링 된 HTML.
Examples
yamd.render('[*hello]');
<p><i>hello</i></p>
highlight(input)
yamd 코드를 구문 강조한다. 출력 형식에 관하여는 yamd.highlighter.pt2hl
을 참조하라.
Parameters
input: string
: yamd 코드.
Returns
string
구문 강조된 코드. HTML로 되어 있다.
Examples
yamd.highlight('[*hello]');
<span class="yamdhl-elem"><span class="yamdhl-lbm">[</span><span class="yamdhl-tn">*</span><span class="yamdhl-sp"></span><span class="yamdhl-tx">hello</span><span class="yamdhl-rbm">]</span></span>
cascade(options)
현재의 글로벌 옵션을 보존하면서 options
로 적당히 덮어 쓴다. yamd.cascade
나 yamd.set
을 한 번도 호출하지 않은 경우 yamd.set
과 효과가 같다.
Parameters
options
: 렌더링 옵션 참조.
Examples
// global options: {}
yamd.cascade({
tags: {
// deletes default element [=]
'=': false
}
});
// global options: {tags: {'=': false}}
yamd.cascade({
tags: {
// overwrites default element behavior of [*].
// wraps content with '*'.
'*': new yamd.renderer.Tag({
name: '*',
display: 'inline',
renderer: (el, options) => {
if (el.innerIsText)
return el.text(`*${el.innerText}*`);
return el.html(`*${el.innerHtml}*`);
}
})
}
});
// global options: {tags: {'=': false, '*': <Function>}}
set(options)
현재의 글로벌 옵션을 버리고 options
로 설정한다. yamd.cascade
나 yamd.set
을 한 번도 호출하지 않은 경우 yamd.cascade
와 효과가 같다. yamd.set({})
으로 글로벌 옵션을 없애버릴 수 있다.
Parameters
options
: 가능한 옵션은 렌더링 옵션 참조.
Examples
// global options: {}
yamd.set({
tags: {
// deletes default element [=]
'=': false
}
});
// global options: {tags: {'=': false}}
yamd.set({
tags: {
// overwrites default element behavior of [*].
// wraps content with '*'.
'*': new yamd.renderer.Tag({
name: '*',
display: 'inline',
renderer: (el, options) => {
if (el.innerIsText)
return el.text(`*${el.innerText}*`);
return el.html(`*${el.innerHtml}*`);
}
})
}
});
// global options: {tags: {'*': <Function>}}
addCodeMirrorMode(CodeMirror)
CodeMirror에 yamd 구문 지원을 추가한다.
Parameters
CodeMirror