Skip to content

Commit

Permalink
fixed #2, meta info support
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Sep 28, 2014
1 parent 70fbd6f commit dc748bb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions examples/data.mdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Demo Timeline

- date: 2014/09/20
- author: @hotoo <hotoo.cn@gmail.com>

----

## Markdown
Expand All @@ -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
Expand Down
27 changes: 25 additions & 2 deletions markline.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,49 @@ 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<l; i++){
var text_line = lines[i];
var match;
if (match = text_line.match(re_title)){
// PARSE TITLE.
data.title = match[1];
} else if (!inline && (match = text_line.match(re_meta))) {
var meta_name = match[1];
var meta_value = match[2];
data.meta[meta_name] = meta_value;
inmeta = true;
} else if (text_line.match(re_hr)){
addGroup("");
} else if (match = text_line.match(re_group)){
// PARSE GRPUPS.
var group_name = match[1];
current_group = group_name;
data.data[current_group] = [];
addGroup(group_name);
} else if (match = text_line.match(re_line)){
// PARSE EVENT LINES.

Expand All @@ -120,6 +141,7 @@ function parse(markdown){
data.data[current_group].push(data_line);
current_line = data_line;

inline = true;
} else if (match = text_line.match(re_event)) {
// PARSE SUB EVENT POINTS.

Expand All @@ -135,6 +157,7 @@ function parse(markdown){
"name": parseMarkdown(name)
});

inline = true;
}
}

Expand Down

0 comments on commit dc748bb

Please sign in to comment.