Skip to content

Commit

Permalink
支持[code][/code]包裹的html代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ksky521 committed Oct 1, 2013
1 parent 0a626c3 commit 9c6644d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
27 changes: 20 additions & 7 deletions lib/md_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,33 @@ var parser = function(string, callback) {
}).join(EOL);
}
var slides = [];
var reg = /\[note\]([\s\S]+)\[\/note\]/im;
var noteReg = /\[note\]([\s\S]+)\[\/note\]/im;
var codeReg = /\[code\]([\s\S]+)\[\/code\]/im;
contents.forEach(function(v, i) {
var cfg = slidesSetting[i];
cfg = cfg.match(/\[slide\s+(.+)\s?\]/);
var attrs = '';
if (cfg) {
attrs = cfg[1];
}
var note = reg.exec(v);
var note = noteReg.exec(v);
if (note) {
v = v.replace(reg, '');
v = v.replace(noteReg, '');
note = marked(note[1]);
}
slides.push(parse(marked(v), note, attrs));
var code = codeReg.exec(v);
var content;
if (code) {
var magicCode = '==%%%%%%%%&THEOWANG&&&&&&&&==';
v = v.replace(codeReg, magicCode);
content = marked(v);
content = content.replace(marked(magicCode), code[1]);
// console.log(content);
} else {
content = marked(v);
}

slides.push(parse(content, note, attrs));
});
//合并
json.content = slides.join(EOL);
Expand Down Expand Up @@ -161,13 +174,13 @@ function parse(str, note, sAttrs) {
article = str;
}
if (head !== '') {
head = do_attr(head);
head = doAttr(head);
head = ['<hgroup>', head, '</hgroup>'].join(EOL);
}

var noHead = !head;
var articleAttr;
article = do_attr(article, true, noHead);
article = doAttr(article, true, noHead);

article = ['<article>', article, '</article>'].join(EOL);
//处理文章只用h1的情况,作为标题页面
Expand Down Expand Up @@ -211,7 +224,7 @@ function parse(str, note, sAttrs) {
return tagStart + note + content + '</slide>';
}

function do_attr(str, isArticle, noHead) {
function doAttr(str, isArticle, noHead) {
//input:## Title {:.build width="200px"}
//output: <h2 class="build" width="200px">Title</h2>
str = str.replace(/<(\w+)>([^<]+)(\s+\{:([^\&].+)\})<\/\1>/gm, function(input, tag, text, idinput, attrs) {
Expand Down
24 changes: 23 additions & 1 deletion ppts/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ nodeppt:https://github.com/ksky521/nodePPT
}
}(window, document));
```
[slide]
## 支持 HTML 语法插入
----
[code]
<div class="file-setting">
<p>这是html</p>
</div>
<p id="css-demo">这是css样式</p>
<p>使用&#91;code]&#91;/code]包裹的代码,会直接插入到页面</p>
<p>具体看下项目中 ppts/demo.md 代码</p>
<script>
function testScriptTag(){

}
console.log(typeof testScriptTag);
</script>
<style>
#css-demo{
color: red;
}
</style>
[/code]

[slide]
## iframe
Expand Down Expand Up @@ -130,8 +152,8 @@ markdown语法如下:
按下键盘【w】键。看下效果。

再按下键盘【w】键。
[slide]

[slide]
## 使用overview模式
---
按下键盘【o】键。看下效果。
Expand Down

0 comments on commit 9c6644d

Please sign in to comment.