Comparing version 1.1.3 to 1.1.4
@@ -75,3 +75,3 @@ var through = require('through3') | ||
.once('error', cb) | ||
.once('eof', function(doc) { | ||
.on('eof', function(doc) { | ||
cb(null, doc); | ||
@@ -118,3 +118,5 @@ }); | ||
deserialize: deserialize, | ||
parser: parser | ||
parser: parser, | ||
Node: require('commonmark/lib/node'), | ||
Parser: require('commonmark').Parser | ||
} |
var through = require('through3') | ||
, Node = require('commonmark/lib/node'); | ||
, Node = require('commonmark/lib/node') | ||
, attach = require('./attach'); | ||
/** | ||
* @private | ||
*/ | ||
function attach(res) { | ||
var n = new Node(res._type, res._sourcepos) | ||
, next = res._firstChild; | ||
for(var k in res) { | ||
n[k] = res[k]; | ||
} | ||
while(next) { | ||
n.appendChild(attach(next)); | ||
next = next._next; | ||
} | ||
return n; | ||
} | ||
/** | ||
* Converts newline delimited JSON to AST nodes. | ||
@@ -43,6 +26,16 @@ * | ||
function transform(ast, encoding, cb) { | ||
//console.error(ast); | ||
//console.error(Boolean(this.doc)); | ||
if(ast && ast._type === 'document') { | ||
this.doc = new Node('document', ast._sourcepos); | ||
}else if(this.doc && ast._type !== 'EOF') { | ||
if(!this.doc) { | ||
this.doc = new Node('document', ast._sourcepos); | ||
}else{ | ||
var next = ast._firstChild; | ||
while(next) { | ||
this.doc.appendChild(attach(next)); | ||
next = next._next; | ||
} | ||
} | ||
}else if(this.doc && ast._type !== 'eof') { | ||
this.doc.appendChild(attach(ast)); | ||
@@ -49,0 +42,0 @@ // got EOF |
@@ -1,11 +0,10 @@ | ||
var through = require('through3'); | ||
var through = require('through3') | ||
, detach = require('./detach'); | ||
function detach(node) { | ||
delete node._firstChild; | ||
delete node._lastChild; | ||
delete node._next; | ||
delete node._prev; | ||
delete node._parent; | ||
function Walk(opts) { | ||
opts = opts || {}; | ||
this.EOF = opts.eof; | ||
} | ||
/** | ||
@@ -39,4 +38,9 @@ * Stream transform. | ||
// @todo allow not sending EOF for mkcat(1) | ||
// @todo which injects it's own eof | ||
// extension to signal end of document | ||
this.push({_type: 'EOF'}); | ||
if(this.EOF !== false) { | ||
this.push({_type: 'eof'}); | ||
} | ||
} | ||
@@ -46,2 +50,2 @@ cb(); | ||
module.exports = through.transform(transform); | ||
module.exports = through.transform(transform, {ctor: Walk}); |
{ | ||
"name": "mkast", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Commonmark AST transformer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
16660
22
371