copy new tests to test/new. have --fix add heading id's to original tests.

This commit is contained in:
Christopher Jeffrey 2013-08-04 06:52:02 -05:00
parent 3b2d4bdef6
commit 6dca44b2d9
4 changed files with 21 additions and 6 deletions

View File

@ -324,13 +324,13 @@ function fix(options) {
// node fix.js
var dir = __dirname + '/tests';
// fix unencoded quotes
fs.readdirSync(dir).filter(function(file) {
return path.extname(file) === '.html';
}).forEach(function(file) {
var file = path.join(dir, file)
, html = fs.readFileSync(file, 'utf8');
// fix unencoded quotes
html = html
.replace(/='([^\n']*)'(?=[^<>\n]*>)/g, '=&__APOS__;$1&__APOS__;')
.replace(/="([^\n"]*)"(?=[^<>\n]*>)/g, '=&__QUOT__;$1&__QUOT__;')
@ -339,6 +339,21 @@ function fix(options) {
.replace(/&__QUOT__;/g, '"')
.replace(/&__APOS__;/g, '\'');
// add heading id's
html = html
.replace(/<(h[1-6])>([^<]+)<\/\1>/g, function(s, h, text) {
var id = text
.replace(/&#39;/g, '\'')
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');
id = id.toLowerCase().replace(/\s/g, '-');
return '<' + h + ' id="' + id + '">' + text + '</' + h + '>';
});
fs.writeFileSync(file, html);
});

View File

@ -1,4 +1,4 @@
<h2>foo</h2>
<h2 id="foo">foo</h2>
<ol>
<li><p>bar:</p>
<blockquote>

View File

@ -1,4 +1,4 @@
<h1>A heading</h1> <p>Just a note, I&#39;ve found that I can&#39;t test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They&#39;re also completely <a href="http://google.com/" title="Google">inconsistent</a> with regards to paragraphs in list items.</p> <p>A link. Not anymore.</p> <aside>This will make me fail the test because
<h1 id="a-heading">A heading</h1> <p>Just a note, I&#39;ve found that I can&#39;t test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They&#39;re also completely <a href="http://google.com/" title="Google">inconsistent</a> with regards to paragraphs in list items.</p> <p>A link. Not anymore.</p> <aside>This will make me fail the test because
markdown.js doesnt acknowledge arbitrary html blocks =/</aside> <ul><li><p>List Item 1</p></li><li><p>List Item 2 </p><ul><li>New List Item 1 Hi, this is a list item.</li><li>New List Item 2 Another item <pre><code>Code goes here.
Lots of it...</code></pre></li><li>New List Item 3 The last item</li></ul></li><li><p>List Item 3 The final item.</p></li><li><p>List Item 4 The real final item.</p></li></ul> <p>Paragraph.</p> <blockquote><ul><li>bq Item 1</li><li>bq Item 2 <ul><li>New bq Item 1</li><li>New bq Item 2 Text here</li></ul></li></ul></blockquote> <hr> <blockquote><p> Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again</p></blockquote> <h2>Another Heading</h2> <p>Hello <em>world</em>. Here is a <a href="//hello">link</a>. And an image <img src="src" alt="alt">.</p> <pre><code>Code goes here.
Lots of it...</code></pre></li><li>New List Item 3 The last item</li></ul></li><li><p>List Item 3 The final item.</p></li><li><p>List Item 4 The real final item.</p></li></ul> <p>Paragraph.</p> <blockquote><ul><li>bq Item 1</li><li>bq Item 2 <ul><li>New bq Item 1</li><li>New bq Item 2 Text here</li></ul></li></ul></blockquote> <hr> <blockquote><p> Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again</p></blockquote> <h2 id="another-heading">Another Heading</h2> <p>Hello <em>world</em>. Here is a <a href="//hello">link</a>. And an image <img src="src" alt="alt">.</p> <pre><code>Code goes here.
Lots of it...</code></pre>

View File

@ -9,10 +9,10 @@
<hr>
<p>hello world</p>
<h1>how are you</h1>
<h1 id="how-are-you">how are you</h1>
<p>hello world</p>
<h1>how are you</h1>
<h1 id="how-are-you">how are you</h1>
<p>hello world</p>
<blockquote><p>how are you</p></blockquote>