markdown-js‚ÅHTML5‚ȃR[ƒh‚ð“f‚«o‚·‚悤‚É‚·‚é

markdown-js‚ÍJavaScript»‚ÌMarkdownƒp[ƒT[‚ŁAÅI“I‚ÈHTMLƒR[ƒh‚¾‚¯‚Å‚È‚­A’†ŠÔ“I‚ÈJSONŒ`Ž®‚̃R[ƒh‚à“f‚«o‚µ‚Ä‚­‚ê‚é‚Ì‚ÅŠg’��‚ª‚µ‚â‚·‚­‚È‚Á‚��‚éB

‚ŁA¡‰ñ‚ÍHTML5‚ŏo—Í‚·‚é‚킯‚¾‚¯‚ǁAŽÀÛ‚Ì‚Ç‚¤ˆá‚¤‚©‹ï‘Ì“I‚ȃR[ƒh‚ÅŒ©‚Ä‚Ý‚éB—Ⴆ‚΂�}‚ñ‚Ȋ�L‚��‚Ìmarkdown‚̃eƒLƒXƒg‚ª‚ ‚Á‚½‚Æ‚·‚é‚Æ
# 1

‚È‚É‚©

## 1.1

hoge

## 1.2

fuga

> ˆø—p‚Æ‚©

# 2
## 2.1
### 2.1.1

HTML4(default)‚ł͂�}‚ñ‚Ȋ�L‚��‚ŏo—Í‚³‚ê‚éB
<h1>1</h1>
<h2>1.1</h2>
<p>hoge</p>
<h2>1.2</h2>
<p>fuga</p>
<blockquote><p>ˆø—p‚Æ‚©</p></blockquote>
<h1>2</h1>
<h2>2.1</h2>
<h3>2.1.1</h3>

HTML5‚¾‚Ƃ�}‚ñ‚Ȋ�L‚��B
<section>
<h1>1</h1>
<section>
<h1>1.1</h1>
<p>hoge</p>
</section>
<section>
<h1>1.2</h1>
<p>fuga</p>
<blockquote>
<p>ˆø—p‚Æ‚©</p>
</blockquote>
</section>
</section>
<section>
<h1>2</h1>
<section>
<h1>2.1</h1>
<section>
<h1>2.1.1</h1>
</section>
</section>
</section>

‚�}‚̂悤‚ÉHTML5‚Ń}[ƒNƒAƒbƒv‚·‚éê‡‚ÍŠesection‚²‚Æ‚Éh1‚ðŽg‚¦‚éB—Ⴆ‚΃uƒƒO‚Ì‹LŽ–‚̃^ƒCƒgƒ‹‚¾‚¯•Ê‚̃tƒH[ƒ€‚Å“ü‚ê‚āA–{•ï¿½ï¿½‚Ímarkdown‚ŏ‘‚­‚悤‚ȏꍇ‚¾‚ƁA‚í‚�L‚í‚�L#‚̐”‚𒲐®‚¹‚¸‚ÉŽg‚¦‚é‚Ì‚Å•Ö—˜‚¾‚µAŒã‚©‚ç‚�}‚¤‚µ‚½‚©‚Á‚½[‚Á‚��‚¤‚Æ‚«‚àh1‚µ‚©Žg‚Á‚��‚Ȃ��‚̂ŏC³‚àŠy‚©‚ÆŽv‚¤Bcss‚Í‚¿‚å‚Á‚Æ‚¾‚¯–Ê“|‚©‚ȁH‚Å‚àA¡‚Ísass‚Æ‚©‚ ‚é‚©‚畽‹C‚¾‚æI‘½•ªI

ƒ\[ƒXƒR[ƒh:https://gist.github.com/2879128
markdown.toHTML5 = function(source, dialect, options) {
return markdown.renderJsonML((function to5(tree, level) {
var i, m,
indices = [],
hx = 'h' + level,
n = tree.length,
blocks = [];

if(!n) return [];

function set(start, end) {
blocks.push(['section', ['h1', tree[start][1]]].concat(to5(tree.slice(start + 1, end), level + 1)));
}

for(i = 0; i < n && hx !== tree[i][0]; ++i) blocks.push(tree[i]);
for(i = 0; i < n; ++i) if(hx === tree[i][0]) indices.push(i);
for(i = 0, m = indices.length - 1; i < m; ++i) set(indices[i], indices[i + 1]);
if(indices.length) set(indices[m], n);

return blocks;
})(markdown.toHTMLTree(source, dialect, options), 1));
};



posted by ‰E‹ž | javascript
blog comments powered by Disqus