markdownstream
Advanced tools
Comparing version 0.0.2 to 0.0.3
# Changelog | ||
## 0.0.3 | ||
* Added token.line property to determine which line the token was found on | ||
* Internal cleanup around the Lexer | ||
## 0.0.2 | ||
@@ -4,0 +9,0 @@ |
@@ -1,2 +0,4 @@ | ||
// | ||
var debug = require('debug')('markdownstream:chunk') | ||
// | ||
// Base Chunk type that others inherit from | ||
@@ -39,3 +41,3 @@ // | ||
CodeBlock.prototype = new Chunk | ||
CodeBlock.prototype = new Chunk() | ||
@@ -47,3 +49,3 @@ CodeBlock.prototype.render = function() { | ||
var output = this.content.split(/\n/).join("\n ") | ||
output = " " + output.replace(/ $/, '') | ||
output = " " + output.replace(/ {4}$/, '') | ||
return output | ||
@@ -63,3 +65,3 @@ } | ||
Heading.prototype = new Chunk | ||
Heading.prototype = new Chunk() | ||
@@ -66,0 +68,0 @@ Heading.prototype.render = function() { |
var stream = require('stream') | ||
, lex = require('./lex') | ||
, Lexer = require('./lexer') | ||
, debug = require('debug')('markdownstream') | ||
function MarkdownStream(options) { | ||
this.ctx = {} | ||
this.writable = true | ||
this.buffer = '' | ||
this.emitter = (function(self) { | ||
return function(data) { self.emit('data', data) } | ||
})(this) | ||
this.emitter = this.emitter.bind(this) | ||
this.lexer = new Lexer(this.emitter) | ||
} | ||
MarkdownStream.prototype = new stream | ||
MarkdownStream.prototype = new stream() | ||
MarkdownStream.prototype.emitter = function emitter(data) { | ||
this.emit('data', data) | ||
} | ||
MarkdownStream.prototype.processData = function(data) { | ||
this.buffer += data | ||
this.buffer = lex(this.buffer, this.ctx, this.emitter) | ||
this.buffer = this.lexer.lex(this.buffer) | ||
@@ -28,2 +31,3 @@ return true | ||
if (data) this.processData(data) | ||
this.lexer.flush(this.buffer) | ||
this.emit('end') | ||
@@ -39,3 +43,3 @@ } | ||
var m = new MarkdownStream | ||
var m = new MarkdownStream() | ||
, chunks = [] | ||
@@ -45,2 +49,3 @@ | ||
m.write(doc) | ||
m.end() | ||
@@ -47,0 +52,0 @@ return chunks |
{ | ||
"name": "markdownstream", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Streaming markdown parser that allows round-tripping and patching", | ||
@@ -22,3 +22,6 @@ "main": "lib/", | ||
"tap": "*" | ||
}, | ||
"dependencies": { | ||
"debug": "~0.7.0" | ||
} | ||
} |
@@ -10,3 +10,3 @@ var stream = require('stream') | ||
FakeReadableStream.prototype = new stream | ||
FakeReadableStream.prototype = new stream() | ||
@@ -41,3 +41,3 @@ FakeReadableStream.prototype.pause = function() { | ||
FakeWritableStream.prototype = new stream | ||
FakeWritableStream.prototype = new stream() | ||
@@ -44,0 +44,0 @@ FakeWritableStream.prototype.end = function(data) { |
@@ -9,5 +9,5 @@ var test = require('tap').test | ||
var parser = new MarkdownStream | ||
var parser = new MarkdownStream() | ||
, input = new fakeStream.readable(doc, 10, 10) | ||
, output = new fakeStream.writable | ||
, output = new fakeStream.writable() | ||
@@ -27,5 +27,5 @@ input.pipe(parser).pipe(output) | ||
var parser = new MarkdownStream | ||
var parser = new MarkdownStream() | ||
, input = new fakeStream.readable(doc, 10, 10) | ||
, output = new fakeStream.writable | ||
, output = new fakeStream.writable() | ||
, buffer = '' | ||
@@ -39,3 +39,3 @@ , code = [] | ||
parser.on('data', function(chunk) { | ||
buffer += chunk | ||
@@ -53,3 +53,3 @@ | ||
if (chunk.type == 'heading') { | ||
headings.push(chunk.content) | ||
@@ -68,3 +68,3 @@ } | ||
t.deepEqual(fcode, ["```\nFC1\n\nFC1\n\n```\n", "```foo\nFC2\nFC2\n\n FC2\n```\n"]) | ||
t.deepEqual(codeparsed, ["IC1\nIC1\n\nIC1\n", "\nIC2\n\n", "FC1\n\nFC1\n\n", "FC2\nFC2\n\n FC2\n"]) | ||
t.deepEqual(codeparsed, ["IC1\nIC1\n\nIC1\n", "FC1\n\nFC1\n\n", "FC2\nFC2\n\n FC2\n", "\nIC2\n\n"]) | ||
t.deepEqual(headings, ["H11", "H21", "H12"]) | ||
@@ -79,3 +79,3 @@ t.end() | ||
var parser = new MarkdownStream | ||
var parser = new MarkdownStream() | ||
, output = '' | ||
@@ -86,3 +86,3 @@ | ||
if (chunk.type == 'code_block') { | ||
chunk.tags = 'foo' | ||
@@ -99,3 +99,3 @@ chunk.refresh() | ||
}) | ||
parser.write("# Hello\n\n foobar\n test\n\nThat's that!\n") | ||
@@ -112,1 +112,13 @@ parser.end() | ||
}) | ||
test("can report the line a token was found on", function(t) { | ||
var tokens = MarkdownStream.sync(doc) | ||
, lines = [] | ||
tokens.forEach(function(token){ | ||
if (token.type == 'code_block') lines.push(token.line) | ||
}) | ||
t.deepEqual(lines, [7, 15, 24, 37]) | ||
t.end() | ||
}) |
@@ -14,6 +14,2 @@ # H11 | ||
IC2 | ||
``` | ||
@@ -42,1 +38,4 @@ FC1 | ||
IC2 | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12923
333
1
+ Addeddebug@~0.7.0
+ Addeddebug@0.7.4(transitive)