Skip to content

Commit

Permalink
Match links with whitespace properly
Browse files Browse the repository at this point in the history
Apparently marked doesn't handle this case.
  • Loading branch information
bebraw committed Mar 28, 2012
1 parent bdee2a1 commit e6c7643
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/ghw.js
Expand Up @@ -127,6 +127,12 @@ function transformers() {
return '<a href="' + o.l.replace(' ', '-').toLowerCase() + '.html">' + o.l + '</a>';
}
},
regular_link_with_whitespace: {
pattern: /\[([^\]]+)\]\s+\(([^\)]+)\)/g,
toHTML: function(o) {
return '<a href="' + o.r + '">' + o.l + '</a>';
}
},
paragraphs: {
toHTML: function(o) {
if(o.l) return '<p>' + o.l.split('\n').filter(id).join('</p><p>') + '</p>';
Expand Down
12 changes: 8 additions & 4 deletions lib/tests.js
Expand Up @@ -67,6 +67,10 @@ suite(matchToHTML(t.bracket_link), {
'[[Foo Bar]]': '<a href="foo-bar.html">Foo Bar</a>'
});

suite(matchToHTML(t.regular_link_with_whitespace), {
'[foo] (bar)': '<a href="bar">foo</a>'
});

suite(matchToHTML(t.paragraphs), {
'foo': '<p>foo</p>',
'foo\nbar': '<p>foo</p><p>bar</p>',
Expand All @@ -77,19 +81,19 @@ function matchToAST(o) {
return function(t) {
var ret;

o.match(t, captureAST)
o.match(t, captureAST);

function captureAST(o) {
ret = o;
}

return ret;
}
};
}

function matchToHTML(o) {
return function(t) {
return o.match(t, o.toHTML)
}
return o.match(t, o.toHTML);
};
}

0 comments on commit e6c7643

Please sign in to comment.