Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions converter/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,62 @@
return str;
}

var parseItalic = function(str) {
var italicRegExp = /(\*|_)(.*?)\1/;
var stra = [];
while ((stra = italicRegExp.exec(str)) !== null) {
str = str.replace(stra[0], '<i>' + stra[2] + '</i>')
}
return str;
}

var parseBold = function(str) {
var boldRegExp = /(\*\*)(.*?)\1/;
var stra = [];
while ((stra = boldRegExp.exec(str)) !== null) {
str = str.replace(stra[0], '<b>' + stra[2] + '</b>')
}
return str;
}

var parseStrong = function(str) {
var strongRegExp = /(~~)(.*?)\1/;
var stra = [];
while ((stra = strongRegExp.exec(str)) !== null) {
str = str.replace(stra[0], '<strong>' + stra[2] + '</strong>')
}
return str;
}


var parseHorizontaleLine = function(str) {
var horizontalRegExp = /^(?:([\*\-_] ?)+)\1\1$/gm;
var stra = [];
while ((stra = horizontalRegExp.exec(str)) !== null) {
str = str.replace(stra[0], '\n<hr/>\n');
}
return str;
}

var parseLink = function(str) {
var linkRegExp = /\[([^\[]+)\]\(([^\)]+)\)/;
var stra = [];
while ((stra = linkRegExp.exec(str)) !== null) {
str = str.replace(stra[0], '<a ' + 'href="' + stra[2] + '">' + stra[1] + '</a>');
}
return str;
}


var markdown = {
parse: function (str, strict) {
'use strict';
str = parseHeadline(str);
str = parseBold(str);
str = parseItalic(str);
str = parseStrong(str);
str = parseHorizontaleLine(str);
str = parseLink(str);
return str;
}
};
Expand Down
1 change: 1 addition & 0 deletions converter/tests/features/bold.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<b> en gras </b>
1 change: 1 addition & 0 deletions converter/tests/features/bold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
** en gras **
2 changes: 1 addition & 1 deletion converter/tests/features/h1.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1> This is an H1</h1>
<h1> This is an H1</h1>
2 changes: 1 addition & 1 deletion converter/tests/features/h1.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# This is an H1
# This is an H1
1 change: 1 addition & 0 deletions converter/tests/features/horizontal_line.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<hr/>
1 change: 1 addition & 0 deletions converter/tests/features/horizontal_line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
1 change: 1 addition & 0 deletions converter/tests/features/italic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<i> italic </i>
1 change: 1 addition & 0 deletions converter/tests/features/italic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_ italic _
1 change: 1 addition & 0 deletions converter/tests/features/link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="http://elephorm.com">Elephorm</a>
1 change: 1 addition & 0 deletions converter/tests/features/link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Elephorm](http://elephorm.com)
1 change: 1 addition & 0 deletions converter/tests/features/strong.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<strong> strong </strong>
1 change: 1 addition & 0 deletions converter/tests/features/strong.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~~ strong ~~