Merge branch 'fixes'

This commit is contained in:
Christopher Jeffrey 2012-01-11 09:27:31 -06:00
commit ac880f0b79
44 changed files with 100 additions and 34 deletions

View File

@ -16,27 +16,31 @@ var block = {
hr: /^( *[\-*_]){3,} *\n/, hr: /^( *[\-*_]){3,} *\n/,
heading: /^ *(#{1,6}) *([^\0]+?) *#* *\n+/, heading: /^ *(#{1,6}) *([^\0]+?) *#* *\n+/,
lheading: /^([^\n]+)\n *(=|-){3,}/, lheading: /^([^\n]+)\n *(=|-){3,}/,
blockquote: /^ *>[^\n]*(?:\n *>[^\n]*)*/, blockquote: /^( *>[^\n]+(\n[^\n]+)*)+/,
list: /^( *)([*+-]|\d+\.) [^\0]+?(?:\n{2,}(?! )|\s*$)(?!\1\2|\1\d+\.)/, list: /^( *)([*+-]|\d+\.) [^\0]+?(?:\n{2,}(?! )|\s*$)(?!\1bullet)/,
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/, html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
paragraph: /^([^\n]+\n?(?!body))+\n*/, paragraph: /^([^\n]+\n?(?!body))+\n*/,
text: /^[^\n]+/ text: /^[^\n]+/
}; };
block.list = (function() {
var list = block.list.source;
list = list
.replace('bullet', /(?:[*+-](?!( *[-*]){2,})|\d+\.)/.source)
return new RegExp(list);
})();
block.html = (function() { block.html = (function() {
var html = block.html.source; var html = block.html.source;
html = html html = html
.replace('comment', /<!--[^\0]*?-->/.source) .replace('comment', /<!--[^\0]*?-->/.source)
.replace('closed', /<(\w+)[^\0]+?<\/\1>/.source) .replace('closed', /<(\w+)[^\0]+?<\/\1>/.source)
.replace('closing', /<\w+[^>]*>/.source); .replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source);
// Better regexes: return new RegExp(html);
// .replace('closed', /<(\w+)\b[^\0]*?<\/\1>/.source)
// .replace('closing', /<\w+(?!:\/|@)\b[^>]*>/.source);
return new
RegExp(html);
})(); })();
block.paragraph = (function() { block.paragraph = (function() {
@ -76,9 +80,9 @@ block.lexer = function(str) {
.replace(/\t/g, ' '); .replace(/\t/g, ' ');
str = str.replace( str = str.replace(
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^\n]+)")? *$/gm, /^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +["(]([^\n]+)[")])? *$/gm,
function(__, id, href, title) { function(__, id, href, title) {
links[id] = { links[id.toLowerCase()] = {
href: href, href: href,
title: title title: title
}; };
@ -175,9 +179,6 @@ block.token = function(str, tokens, top) {
cap = cap[0].replace(/^ *>/gm, ''); cap = cap[0].replace(/^ *>/gm, '');
// Better conformance:
// cap = cap[0].replace(/^ *> ?/gm, '');
// Pass `top` to keep the current // Pass `top` to keep the current
// "toplevel" state. This is exactly // "toplevel" state. This is exactly
// how markdown.pl works. // how markdown.pl works.
@ -202,7 +203,7 @@ block.token = function(str, tokens, top) {
// Get each top-level item. // Get each top-level item.
cap = cap[0].match( cap = cap[0].match(
/^( *)([*+-]|\d+\.)[^\n]*(?:\n(?!\1\2|\1\d+\.)[^\n]*)*/gm /^( *)([*+-]|\d+\.)[^\n]*(?:\n(?!\1(?:[*+-]|\d+\.))[^\n]*)*/gm
); );
i = 0; i = 0;
@ -282,16 +283,16 @@ block.token = function(str, tokens, top) {
*/ */
var inline = { var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!_])/, escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/, gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/,
tag: /^<!--[^\0]*?-->|^<\/?\w+[^>]*>/, tag: /^<!--[^\0]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^>])*>/,
link: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\(([^\)]*)\)/, link: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\[|\](?=[^[\]]*\]))*)\]\(([^\)]*)\)/,
reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\s*\[([^\]]*)\]/, reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\[|\](?=[^[\]]*\]))*)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
strong: /^__(?=\S)([^\0]*?\S)__(?!_)|^\*\*(?=\S)([^\0]*?\S)\*\*(?!\*)/, strong: /^__(?=\S)([^\0]*?\S)__(?!_)|^\*\*(?=\S)([^\0]*?\S)\*\*(?!\*)/,
em: /^\b_(?=\S)([^\0]*?\S)_\b|^\*(?=\S)([^\0]*?\S)\*/, em: /^\b_(?=\S)([^\0]*?\S)_\b|^\*(?=\S)((?:\*\*|[^\0])*?)\*(?!\*)/,
code: /^`([^`]+)`|^``([^\0]+?)``/, code: /^(`+)([^\0]*?[^`])\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/, br: /^ {2,}\n(?!\s*$)/,
text: /^[^\0]+?(?=body|$)/ text: /^[^\0]+?(?=body|$)/
}; };
@ -382,6 +383,11 @@ inline.lexer = function(str) {
if (cap = inline.link.exec(str)) { if (cap = inline.link.exec(str)) {
str = str.substring(cap[0].length); str = str.substring(cap[0].length);
text = /^\s*<?([^\s]*?)>?(?:\s+"([^\n]+)")?\s*$/.exec(cap[2]); text = /^\s*<?([^\s]*?)>?(?:\s+"([^\n]+)")?\s*$/.exec(cap[2]);
if (!text) {
out += cap[0][0];
str = cap[0].substring(1) + str;
continue;
}
link = { link = {
href: text[1], href: text[1],
title: text[2] title: text[2]
@ -395,7 +401,7 @@ inline.lexer = function(str) {
|| (cap = inline.nolink.exec(str))) { || (cap = inline.nolink.exec(str))) {
str = str.substring(cap[0].length); str = str.substring(cap[0].length);
link = (cap[2] || cap[1]).replace(/\s+/g, ' '); link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
link = links[link]; link = links[link.toLowerCase()];
if (!link) { if (!link) {
out += cap[0][0]; out += cap[0][0];
str = cap[0].substring(1) + str; str = cap[0].substring(1) + str;

View File

@ -60,14 +60,6 @@ fs.readdirSync(dir).forEach(function(file) {
fs.writeFileSync(file, html); fs.writeFileSync(file, html);
})(); })();
// fix bad grammar
(function() {
var file = dir + '/ordered_and_unordered_lists.text';
var text = fs.readFileSync(file, 'utf8');
text = text.replace(/(\n\*\sasterisk\s3\n\n)(\*\s\*\s\*)/, '$1\n$2');
fs.writeFileSync(file, text);
})();
// fix strange markup that isnt likely // fix strange markup that isnt likely
// to exist in the reality // to exist in the reality
(function _(ext) { (function _(ext) {

View File

@ -101,10 +101,11 @@ main.bench = function(name, func) {
load(); load();
// remove these as they affect the // remove these as they affect the
// comparison to older benchmark times. // comparison to older benchmark times.
Object.keys(files).forEach(function(name) { fs.readdirSync(__dirname + '/new').forEach(function(name) {
if (name.indexOf('gfm') === 0) delete files[name]; if (name.split('.').pop() === 'html') return;
if (name === 'main.text') return;
delete files[name];
}); });
delete files['toplevel_paragraphs.text'];
} }
var start = Date.now() var start = Date.now()

View File

@ -0,0 +1 @@
<p><a href="/url">hi</a></p>

View File

@ -0,0 +1,3 @@
[hi]
[HI]: /url

View File

@ -0,0 +1 @@
<div style=">"/>

View File

@ -0,0 +1 @@
<div style=">"/>

View File

@ -0,0 +1,4 @@
<blockquote>
<p>hi there
bud</p>
</blockquote>

View File

@ -0,0 +1,2 @@
> hi there
bud

View File

@ -0,0 +1 @@
<p>></p>

View File

@ -0,0 +1 @@
\>

View File

@ -0,0 +1 @@
<p><code>hi ther `` ok ```</code></p>

View File

@ -0,0 +1 @@
````` hi ther `` ok ``` `````

1
test/new/nested_em.html Normal file
View File

@ -0,0 +1 @@
<p><em>test <strong>test</strong></em></p>

1
test/new/nested_em.text Normal file
View File

@ -0,0 +1 @@
*test **test***

View File

@ -0,0 +1 @@
<p><a href="/url">the <code>]</code> character</a></p>

View File

@ -0,0 +1 @@
[the `]` character](/url)

1
test/new/not_a_link.html Normal file
View File

@ -0,0 +1 @@
<p>\[test](not a link)</p>

1
test/new/not_a_link.text Normal file
View File

@ -0,0 +1 @@
\\[test](not a link)

1
test/new/ref_paren.html Normal file
View File

@ -0,0 +1 @@
<p><a href="/url" title="there">hi</a></p>

3
test/new/ref_paren.text Normal file
View File

@ -0,0 +1,3 @@
[hi]
[hi]: /url (there)

5
test/new/sublist.html Normal file
View File

@ -0,0 +1,5 @@
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>

3
test/new/sublist.text Normal file
View File

@ -0,0 +1,3 @@
* test
+ test
- test

View File

@ -0,0 +1 @@
<p><a href="/url">hi</a></p>

View File

@ -0,0 +1,3 @@
[hi]
[HI]: /url

View File

@ -0,0 +1 @@
<div style=">"/>

View File

@ -0,0 +1 @@
<div style=">"/>

View File

@ -0,0 +1,4 @@
<blockquote>
<p>hi there
bud</p>
</blockquote>

View File

@ -0,0 +1,2 @@
> hi there
bud

View File

@ -0,0 +1 @@
<p>></p>

View File

@ -0,0 +1 @@
\>

View File

@ -0,0 +1 @@
<p><code>hi ther `` ok ```</code></p>

View File

@ -0,0 +1 @@
````` hi ther `` ok ``` `````

View File

@ -0,0 +1 @@
<p><em>test <strong>test</strong></em></p>

View File

@ -0,0 +1 @@
*test **test***

View File

@ -0,0 +1 @@
<p><a href="/url">the <code>]</code> character</a></p>

View File

@ -0,0 +1 @@
[the `]` character](/url)

View File

@ -0,0 +1 @@
<p>\[test](not a link)</p>

View File

@ -0,0 +1 @@
\\[test](not a link)

View File

@ -15,7 +15,6 @@ Asterisks loose:
* asterisk 3 * asterisk 3
* * * * * *
Pluses tight: Pluses tight:

View File

@ -0,0 +1 @@
<p><a href="/url" title="there">hi</a></p>

View File

@ -0,0 +1,3 @@
[hi]
[hi]: /url (there)

5
test/tests/sublist.html Normal file
View File

@ -0,0 +1,5 @@
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>

3
test/tests/sublist.text Normal file
View File

@ -0,0 +1,3 @@
* test
+ test
- test