From dc748bb4c3e88f0b25379222ce84ad175eec5c1c Mon Sep 17 00:00:00 2001 From: hotoo Date: Sun, 28 Sep 2014 12:32:18 +0800 Subject: [PATCH] fixed #2, meta info support --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- examples/data.mdown | 6 ++++++ markline.js | 27 +++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d682ae6..5b59ae0 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,46 @@ Markline use subsets of markdown now: * `* list item`, `- another list item` for lines. * ` * sub list item`, ` - another sub list item` for events. -### Others +### Horizontal + +for anonymous group. + +```markdown +---- +```` + +### Link + +```markdown +[link](url) +``` + +### Image + +```markdown +![alt](image-url) +``` + +### Strong + +```markdown +**strong** +__another strong__ +``` + +### Italic + +```markdown +_italic_ +*another italic* +``` + +### Delete + +```markdown +~delete~ +~~another delete~~ +``` More markdown syntax support maybe in the feature. diff --git a/examples/data.mdown b/examples/data.mdown index f9e0555..5d9071b 100644 --- a/examples/data.mdown +++ b/examples/data.mdown @@ -1,6 +1,9 @@ # Demo Timeline +- date: 2014/09/20 +- author: @hotoo + ---- ## Markdown @@ -18,6 +21,9 @@ - 2003/02 event point at month - 2000/08/08 event point at date - 2004/06/01~2004 event range from date to year + +---- + * 2000~2001 year to another year * 2000/06~2001 month to year * 2000/06/16~2001 date to year diff --git a/markline.js b/markline.js index 5d78fba..81a0f6d 100644 --- a/markline.js +++ b/markline.js @@ -78,16 +78,31 @@ function parse(markdown){ var lines = markdown.split(/\r\n|\r|\n/); var data = { title: "", + meta: {}, data: {} }; var re_title = /^#\s+(.*)$/; + var re_meta = /^[\-\*]\s+([^:]+):\s*(.*)$/; + var re_hr = /^\-{2,}$/; var re_group = /^##+\s+(.*)$/; var re_line = /^[\*\-]\s+(([0-9\/\-]+)(?:~([0-9\/\-]*))?)\s+(.*)$/; var re_event = /^\s+[\*\-]\s+(([0-9\/\-]+)(?:~([0-9\/\-]*))?)\s+(.*)$/; var current_group = ""; var current_line; + var inline = false; // into group, line, or event body. + var inmeta = false; + + function addGroup(group_name){ + if (data.data.hasOwnProperty(group_name)) { + group_name += " "; + } + current_group = group_name; + data.data[current_group] = []; + + inline = true; + } for(var i=0,l=lines.length; i