From 1471d80bf7078a23bc0286f442a9c32b08aae0a9 Mon Sep 17 00:00:00 2001 From: sabativi Date: Mon, 20 Jul 2015 14:26:52 +0200 Subject: [PATCH 1/2] add horizontal line to parser --- converter/markdown.js | 10 ++++++++++ converter/tests/features/horizontal_line.html | 1 + converter/tests/features/horizontal_line.md | 1 + 3 files changed, 12 insertions(+) create mode 100644 converter/tests/features/horizontal_line.html create mode 100644 converter/tests/features/horizontal_line.md diff --git a/converter/markdown.js b/converter/markdown.js index 7b21365..af92788 100644 --- a/converter/markdown.js +++ b/converter/markdown.js @@ -8,10 +8,20 @@ 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
\n'); + } + return str; + } + var markdown = { parse: function (str, strict) { 'use strict'; str = parseHeadline(str); + str = parseHorizontaleLine(str); return str; } }; diff --git a/converter/tests/features/horizontal_line.html b/converter/tests/features/horizontal_line.html new file mode 100644 index 0000000..e2c5e31 --- /dev/null +++ b/converter/tests/features/horizontal_line.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/converter/tests/features/horizontal_line.md b/converter/tests/features/horizontal_line.md new file mode 100644 index 0000000..73b314f --- /dev/null +++ b/converter/tests/features/horizontal_line.md @@ -0,0 +1 @@ +--- \ No newline at end of file From b82c5f0ef93d7641c14490377cb071302b937bc9 Mon Sep 17 00:00:00 2001 From: sabativi Date: Mon, 20 Jul 2015 17:17:33 +0200 Subject: [PATCH 2/2] tp4-start commit add bold in parser add link in parser add italic in parser replace string with bold and add proper bold definition --- converter/markdown.js | 42 ++++++++++++++++++++++++++++ converter/tests/features/bold.html | 1 + converter/tests/features/bold.md | 1 + converter/tests/features/h1.html | 2 +- converter/tests/features/h1.md | 2 +- converter/tests/features/italic.html | 1 + converter/tests/features/italic.md | 1 + converter/tests/features/link.html | 1 + converter/tests/features/link.md | 1 + converter/tests/features/strong.html | 1 + converter/tests/features/strong.md | 1 + 11 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 converter/tests/features/bold.html create mode 100644 converter/tests/features/bold.md create mode 100644 converter/tests/features/italic.html create mode 100644 converter/tests/features/italic.md create mode 100644 converter/tests/features/link.html create mode 100644 converter/tests/features/link.md create mode 100644 converter/tests/features/strong.html create mode 100644 converter/tests/features/strong.md diff --git a/converter/markdown.js b/converter/markdown.js index af92788..4b52839 100644 --- a/converter/markdown.js +++ b/converter/markdown.js @@ -8,6 +8,34 @@ return str; } + var parseItalic = function(str) { + var italicRegExp = /(\*|_)(.*?)\1/; + var stra = []; + while ((stra = italicRegExp.exec(str)) !== null) { + str = str.replace(stra[0], '' + stra[2] + '') + } + return str; +} + +var parseBold = function(str) { + var boldRegExp = /(\*\*)(.*?)\1/; + var stra = []; + while ((stra = boldRegExp.exec(str)) !== null) { + str = str.replace(stra[0], '' + stra[2] + '') + } + return str; + } + +var parseStrong = function(str) { + var strongRegExp = /(~~)(.*?)\1/; + var stra = []; + while ((stra = strongRegExp.exec(str)) !== null) { + str = str.replace(stra[0], '' + stra[2] + '') + } + return str; +} + + var parseHorizontaleLine = function(str) { var horizontalRegExp = /^(?:([\*\-_] ?)+)\1\1$/gm; var stra = []; @@ -17,11 +45,25 @@ return str; } + var parseLink = function(str) { + var linkRegExp = /\[([^\[]+)\]\(([^\)]+)\)/; + var stra = []; + while ((stra = linkRegExp.exec(str)) !== null) { + str = str.replace(stra[0], '' + stra[1] + ''); + } + 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; } }; diff --git a/converter/tests/features/bold.html b/converter/tests/features/bold.html new file mode 100644 index 0000000..84e8209 --- /dev/null +++ b/converter/tests/features/bold.html @@ -0,0 +1 @@ + en gras \ No newline at end of file diff --git a/converter/tests/features/bold.md b/converter/tests/features/bold.md new file mode 100644 index 0000000..7726932 --- /dev/null +++ b/converter/tests/features/bold.md @@ -0,0 +1 @@ +** en gras ** \ No newline at end of file diff --git a/converter/tests/features/h1.html b/converter/tests/features/h1.html index 1ef88d7..50a431d 100644 --- a/converter/tests/features/h1.html +++ b/converter/tests/features/h1.html @@ -1 +1 @@ -

This is an H1

+

This is an H1

\ No newline at end of file diff --git a/converter/tests/features/h1.md b/converter/tests/features/h1.md index 90944c9..f6a39e1 100644 --- a/converter/tests/features/h1.md +++ b/converter/tests/features/h1.md @@ -1 +1 @@ -# This is an H1 +# This is an H1 \ No newline at end of file diff --git a/converter/tests/features/italic.html b/converter/tests/features/italic.html new file mode 100644 index 0000000..807880b --- /dev/null +++ b/converter/tests/features/italic.html @@ -0,0 +1 @@ + italic \ No newline at end of file diff --git a/converter/tests/features/italic.md b/converter/tests/features/italic.md new file mode 100644 index 0000000..9a6e757 --- /dev/null +++ b/converter/tests/features/italic.md @@ -0,0 +1 @@ +_ italic _ \ No newline at end of file diff --git a/converter/tests/features/link.html b/converter/tests/features/link.html new file mode 100644 index 0000000..14c71d0 --- /dev/null +++ b/converter/tests/features/link.html @@ -0,0 +1 @@ +Elephorm \ No newline at end of file diff --git a/converter/tests/features/link.md b/converter/tests/features/link.md new file mode 100644 index 0000000..92d79db --- /dev/null +++ b/converter/tests/features/link.md @@ -0,0 +1 @@ +[Elephorm](http://elephorm.com) \ No newline at end of file diff --git a/converter/tests/features/strong.html b/converter/tests/features/strong.html new file mode 100644 index 0000000..2ebfedd --- /dev/null +++ b/converter/tests/features/strong.html @@ -0,0 +1 @@ + strong \ No newline at end of file diff --git a/converter/tests/features/strong.md b/converter/tests/features/strong.md new file mode 100644 index 0000000..ff651bb --- /dev/null +++ b/converter/tests/features/strong.md @@ -0,0 +1 @@ +~~ strong ~~ \ No newline at end of file