diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/markdown | 2 | ||||
-rwxr-xr-x | js/stmd.js | 19 | ||||
-rwxr-xr-x | js/test.js | 19 |
3 files changed, 22 insertions, 18 deletions
diff --git a/js/markdown b/js/markdown index 05a372a..2b23d54 100755 --- a/js/markdown +++ b/js/markdown @@ -11,5 +11,5 @@ fs.readFile(file, 'utf8', function(err, data) { } var parser = new stmd.DocParser(); var renderer = new stmd.HtmlRenderer(); - console.log(renderer.render(parser.parse(data))); + process.stdout.write(renderer.render(parser.parse(data))); }); @@ -1,4 +1,4 @@ -// stmd.js - "standard markdown" in javascript +// stmd.js - CommomMark in javascript // Copyright (C) 2014 John MacFarlane // License: BSD3. @@ -373,7 +373,7 @@ var parseEmphasis = function(inlines) { return (this.pos - startpos); default: - return result; + return res; } return 0; @@ -382,7 +382,7 @@ var parseEmphasis = function(inlines) { // Attempt to parse link title (sans quotes), returning the string // or null if no match. var parseLinkTitle = function() { - title = this.match(reLinkTitle); + var title = this.match(reLinkTitle); if (title) { // chop off quotes from title and unescape: return unescape(title.substr(1, title.length - 2)); @@ -861,7 +861,7 @@ var parseListMarker = function(ln, offset) { } else { return null; } - blank_item = match[0].length === rest.length; + var blank_item = match[0].length === rest.length; if (spaces_after_marker >= 5 || spaces_after_marker < 1 || blank_item) { @@ -926,7 +926,7 @@ var incorporateLine = function(ln, line_number) { switch (container.t) { case 'BlockQuote': - matched = indent <= 3 && ln[first_nonspace] === '>'; + var matched = indent <= 3 && ln[first_nonspace] === '>'; if (matched) { offset = first_nonspace + 1; if (ln[offset] === ' ') { @@ -1234,7 +1234,7 @@ var finalize = function(block, line_number) { if (line_number > block.start_line) { block.end_line = line_number - 1; } else { - block_end_line = line_number; + block.end_line = line_number; } switch (block.t) { @@ -1478,9 +1478,10 @@ var renderBlock = function(block, in_tight_list) { case 'FencedCode': info_words = block.info.split(/ +/); attr = info_words.length === 0 || info_words[0].length === 0 ? - [] : [['class',this.escape(info_words[0],true)]]; - return inTags('pre', attr, - inTags('code', [], this.escape(block.string_content))); + [] : [['class','language-' + + this.escape(info_words[0],true)]]; + return inTags('pre', [], + inTags('code', attr, this.escape(block.string_content))); case 'HtmlBlock': return block.string_content; case 'ReferenceDef': @@ -1,9 +1,8 @@ #!/usr/bin/env node var fs = require('fs'); -var util = require('util'); var stmd = require('./stmd'); -var ansi = require('./ansi/ansi') +var ansi = require('./ansi/ansi'); var cursor = ansi(process.stdout); var writer = new stmd.HtmlRenderer(); @@ -15,19 +14,23 @@ var failed = 0; var showSpaces = function(s) { var t = s; return t.replace(/\t/g,'→') - .replace(/ /g,'␣'); -} + .replace(/ /g,'␣'); +}; fs.readFile('spec.txt', 'utf8', function(err, data) { if (err) { return console.log(err); } + var i; var examples = []; var current_section = ""; var example_number = 0; - tests = data.replace(/^<!-- END TESTS -->(.|[\n])*/m,''); + var tests = data + .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence + .replace(/^<!-- END TESTS -->(.|[\n])*/m, ''); + tests.replace(/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/gm, - function(_,x,y,z,w){ + function(_,x,y,z){ if (z) { current_section = z; } else { @@ -45,7 +48,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) { for (i = 0; i < examples.length; i++) { var example = examples[i]; - if (example.section != current_section) { + if (example.section !== current_section) { if (current_section !== '') { cursor.write('\n'); } @@ -53,7 +56,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) { cursor.reset().write(current_section).reset().write(' '); } var actual = writer.renderBlock(reader.parse(example.markdown.replace(/→/g, '\t'))); - if (actual == example.html) { + if (actual === example.html) { passed++; cursor.green().write('✓').reset(); } else { |