@zkochan/unified
Advanced tools
Comparing version 0.1.0 to 0.2.0
29
index.js
@@ -30,2 +30,3 @@ /** | ||
.use(function (ctx) { | ||
if (ctx.tree) return; | ||
return ctx.context.parse(ctx.file, ctx.settings) | ||
@@ -166,2 +167,8 @@ .then(tree => { ctx.tree = tree }); | ||
function createParser (value, settings) { | ||
var file = new VFile(value); | ||
var CustomParser = (this && this.Parser) || Parser; | ||
return new CustomParser(file, settings, instance(this)) | ||
} | ||
/** | ||
@@ -181,4 +188,3 @@ * Parse a file. | ||
var file = new VFile(value); | ||
var CustomParser = (this && this.Parser) || Parser; | ||
var nodePromise = new CustomParser(file, settings, instance(this)).parse(); | ||
var nodePromise = this.createParser(file, settings).parse(); | ||
@@ -247,15 +253,19 @@ return nodePromise.then(node => { | ||
var self = instance(this); | ||
var file = new VFile(value); | ||
var opts = { | ||
'context': self, | ||
'settings': settings || {} | ||
} | ||
if (typeof value === 'string' || value instanceof VFile) { | ||
opts.file = new VFile(value); | ||
} else { | ||
opts.tree = value; | ||
} | ||
var result = null; | ||
return new Promise((resolve, reject) => { | ||
pipeline.run({ | ||
'context': self, | ||
'file': file, | ||
'settings': settings || {} | ||
}, function (err, res) { | ||
pipeline.run(opts, function (err, res) { | ||
if (err) return reject(err) | ||
resolve({ | ||
file, | ||
file: opts.file, | ||
result: res && res.result | ||
@@ -279,2 +289,3 @@ }) | ||
Processor.data = proto.data = data || null; | ||
Processor.createParser = proto.createParser = createParser | ||
@@ -281,0 +292,0 @@ return Processor; |
{ | ||
"name": "@zkochan/unified", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Text processing framework: Parse / Transform / Compile", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
24173
249