From c41100a58a5670bb42f01a9f19625f1125f6c8c1 Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Mon, 2 Dec 2013 23:18:20 +0100 Subject: [PATCH 1/5] Added support for Markdown style links. Fixes issue #5. --- index.html | 6 ++++++ life.example.md | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 73706cc..9ca022c 100644 --- a/index.html +++ b/index.html @@ -231,6 +231,12 @@ h1{ } } + // Parse Markdown links in the text + // credit: http://stackoverflow.com/a/9268827 + var link = d.text.match(/\[([^\]]+)\]\(([^)]+)\)/); + if (link) + d.text = d.text.replace(link[0], "" + link[1] + ""); + return '
' + d.time.title + ' ' + d.text + '  
'; return ''; }, diff --git a/life.example.md b/life.example.md index 42c5317..6cfd821 100644 --- a/life.example.md +++ b/life.example.md @@ -2,7 +2,7 @@ =============== - 24/02/1955 Born -- ~1968 Summer job +- ~1968 Summer [job](http://en.wikipedia.org/wiki/Beach)! - 03/1976 Built a computer - 01/04/1976 Started a company - 04/1976-2011 Whole bunch of interesting events \ No newline at end of file From 3e98a54109498bc025dd38365b8cccb5856d9f53 Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Mon, 2 Dec 2013 23:53:48 +0100 Subject: [PATCH 2/5] Fixed Markdown link detection to support multiple instances. Fixes issue #5. --- index.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 9ca022c..7613823 100644 --- a/index.html +++ b/index.html @@ -233,10 +233,11 @@ h1{ // Parse Markdown links in the text // credit: http://stackoverflow.com/a/9268827 - var link = d.text.match(/\[([^\]]+)\]\(([^)]+)\)/); - if (link) + var link = null; + while(link = d.text.match(/\[([^\]]+)\]\(([^)]+)\)/)) { d.text = d.text.replace(link[0], "" + link[1] + ""); - + } + return '
' + d.time.title + ' ' + d.text + '  
'; return ''; }, From 66197d54ee6fd9125db90d153369c4dba6378252 Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Tue, 3 Dec 2013 19:59:14 +0100 Subject: [PATCH 3/5] Added support for tooltips inside Markdown links. --- index.html | 8 ++++++-- life.example.md | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 7613823..d25c49a 100644 --- a/index.html +++ b/index.html @@ -234,8 +234,12 @@ h1{ // Parse Markdown links in the text // credit: http://stackoverflow.com/a/9268827 var link = null; - while(link = d.text.match(/\[([^\]]+)\]\(([^)]+)\)/)) { - d.text = d.text.replace(link[0], "" + link[1] + ""); + while(link = d.text.match(/\[([^\]]+)\]\(([^)"]+)(?: \"([^\"]+)\")*\)/)) { + var link_attr = ""; + if (link[3] !== undefined) { + link_attr = " title='" + link[3] + "'"; + } + d.text = d.text.replace(link[0], "" + link[1] + ""); } return '
' + d.time.title + ' ' + d.text + '  
'; diff --git a/life.example.md b/life.example.md index 6cfd821..f1285be 100644 --- a/life.example.md +++ b/life.example.md @@ -2,7 +2,7 @@ =============== - 24/02/1955 Born -- ~1968 Summer [job](http://en.wikipedia.org/wiki/Beach)! +- ~1968 Summer [job](http://en.wikipedia.org/wiki/Beach "Job...")! - 03/1976 Built a computer - 01/04/1976 Started a company - 04/1976-2011 Whole bunch of interesting events \ No newline at end of file From 91f10f9b40af86b36645ea27f59ce277bf2d3e4e Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Tue, 3 Dec 2013 20:12:56 +0100 Subject: [PATCH 4/5] Use ? instead of * to match tooltips in Markdown links. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index d25c49a..6d66b89 100644 --- a/index.html +++ b/index.html @@ -234,7 +234,7 @@ h1{ // Parse Markdown links in the text // credit: http://stackoverflow.com/a/9268827 var link = null; - while(link = d.text.match(/\[([^\]]+)\]\(([^)"]+)(?: \"([^\"]+)\")*\)/)) { + while(link = d.text.match(/\[([^\]]+)\]\(([^)"]+)(?: \"([^\"]+)\")?\)/)) { var link_attr = ""; if (link[3] !== undefined) { link_attr = " title='" + link[3] + "'"; From f9f8f7942582b1ac2dd6ba8c74f3e9c3ef1ffd05 Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Wed, 4 Dec 2013 08:51:56 +0100 Subject: [PATCH 5/5] Added a more meaningful example. --- life.example.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/life.example.md b/life.example.md index f1285be..89356cb 100644 --- a/life.example.md +++ b/life.example.md @@ -2,7 +2,7 @@ =============== - 24/02/1955 Born -- ~1968 Summer [job](http://en.wikipedia.org/wiki/Beach "Job...")! +- ~1968 Summer job - 03/1976 Built a computer -- 01/04/1976 Started a company +- 01/04/1976 Started a [company](http://en.wikipedia.org/wiki/Apple_Inc. "Apple Inc.") - 04/1976-2011 Whole bunch of interesting events \ No newline at end of file