Comparing version 1.1.4 to 1.1.5
14
index.js
@@ -90,2 +90,3 @@ var through = require('through3') | ||
* @param {Object} buffer input AST. | ||
* @param {Object} [opts] processing options. | ||
* @param {Function} [cb] callback function. | ||
@@ -95,6 +96,13 @@ * | ||
*/ | ||
function serialize(buffer, cb) { | ||
var ast = new Walk() | ||
, serializer = new Serialize(); | ||
function serialize(buffer, opts, cb) { | ||
if(typeof opts === 'function') { | ||
cb = opts; | ||
opts = null; | ||
} | ||
opts = opts || {}; | ||
var ast = new Walk(opts) | ||
, serializer = new Serialize(opts); | ||
ast.pipe(serializer); | ||
@@ -101,0 +109,0 @@ |
@@ -23,2 +23,3 @@ var Node = require('commonmark/lib/node'); | ||
} | ||
return n; | ||
@@ -25,0 +26,0 @@ } |
@@ -26,8 +26,7 @@ var through = require('through3') | ||
function transform(ast, encoding, cb) { | ||
//console.error(ast); | ||
//console.error(Boolean(this.doc)); | ||
// create root document | ||
if(ast && ast._type === 'document') { | ||
if(!this.doc) { | ||
this.doc = new Node('document', ast._sourcepos); | ||
// append nested document | ||
}else{ | ||
@@ -34,0 +33,0 @@ var next = ast._firstChild; |
var through = require('through3') | ||
, stringify = require('./stringify') | ||
, EOL = require('os').EOL; | ||
function circular() { | ||
var seen = []; | ||
return function (key, val) { | ||
var invalid = key === '_parent' || key === '_prev' || key === '_lastChild' | ||
|| (val === null) | ||
|| Boolean(~seen.indexOf(val)); | ||
if(invalid) { | ||
return; | ||
} | ||
if(!val || typeof (val) !== 'object') { | ||
return val; | ||
} | ||
seen.push(val); | ||
return val; | ||
}; | ||
function Serializer(opts) { | ||
opts = opts || {}; | ||
this.indent = opts.indent || 0; | ||
} | ||
@@ -31,6 +20,6 @@ | ||
function transform(ast, encoding, cb) { | ||
this.push(JSON.stringify(ast, circular()) + EOL); | ||
this.push(stringify(ast, this.indent) + EOL); | ||
cb(); | ||
} | ||
module.exports = through.transform(transform); | ||
module.exports = through.transform(transform, {ctor: Serializer}); |
@@ -9,3 +9,2 @@ var through = require('through3') | ||
/** | ||
@@ -22,6 +21,7 @@ * Stream transform. | ||
var nodes = []; | ||
if(ast && ast.type === 'document' && ast.firstChild) { | ||
if(ast && ast.type === 'document' && ast._firstChild) { | ||
//if(ast && ast._firstChild) { | ||
// push direct descendants | ||
var next = ast.firstChild; | ||
var next = ast._firstChild; | ||
while(next) { | ||
@@ -40,5 +40,2 @@ nodes.push(next); | ||
// @todo allow not sending EOF for mkcat(1) | ||
// @todo which injects it's own eof | ||
// extension to signal end of document | ||
@@ -48,2 +45,4 @@ if(this.EOF !== false) { | ||
} | ||
}else{ | ||
this.push(ast); | ||
} | ||
@@ -50,0 +49,0 @@ cb(); |
{ | ||
"name": "mkast", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Commonmark AST transformer", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"commonmark": "tmpfs/commonmark.js", | ||
"stream-lines": "~1.1.7", | ||
"stream-lines": "~1.2.0", | ||
"through3": "~1.1.5" | ||
@@ -27,0 +27,0 @@ }, |
@@ -7,3 +7,2 @@ var expect = require('chai').expect | ||
, Walk = require('../../lib/walk') | ||
//, Deserialize = require('../../lib/deserialize') | ||
, ParserStream = require('../../lib/parser'); | ||
@@ -13,2 +12,17 @@ | ||
it('should serialize and deserialize list w/ callback', function(done) { | ||
var parser = new Parser() | ||
, buffer = parser.parse('* foo\n* bar\n') | ||
, expected = (new Renderer()).render(buffer); | ||
function complete(err, doc) { | ||
expect(doc).to.be.an('object'); | ||
expect((new Renderer()).render(doc)).to.eql(expected); | ||
done(); | ||
} | ||
ast.deserialize(ast.serialize(buffer), complete); | ||
}); | ||
it('should serialize ast w/ callback', function(done) { | ||
@@ -40,4 +54,3 @@ var parser = new Parser() | ||
, buffer = parser.parse('# Title\n<? @include file.md ?>') | ||
, expected = (new Renderer()).render(buffer) | ||
//, deserializer = new Deserialize(); | ||
, expected = (new Renderer()).render(buffer); | ||
@@ -44,0 +57,0 @@ function complete(err, doc) { |
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
18369
24
433
+ Addedstream-lines@1.2.1(transitive)
- Removedstream-lines@1.1.8(transitive)
Updatedstream-lines@~1.2.0