gulp-marked
Advanced tools
Comparing version 0.1.0 to 0.2.0
52
index.js
var es = require('event-stream'); | ||
var marked = require('marked'); | ||
var BufferStreams = require('bufferstreams'); | ||
module.exports = function(opt) { | ||
// File level transform function | ||
function fileMarked(opt) { | ||
// Return a callback function handling the buffered content | ||
return function(err, buf, cb) { | ||
// Handle any error | ||
if(err) throw err; | ||
// Use the buffered content | ||
marked(String(buf), opt, function (err, content) { | ||
// Report any error with the callback | ||
if (err) { | ||
cb(err); | ||
// Give the transformed buffer back | ||
} else { | ||
cb(null, content); | ||
} | ||
}); | ||
}; | ||
} | ||
// Plugin function | ||
function gulpMarked(opt) { | ||
marked.setOptions(opt || {}); | ||
return es.map(function (file, callback) { | ||
marked(String(file.contents), function (err, content) { | ||
if (!err) file.contents = content; | ||
callback(err, file); | ||
}); | ||
console.log(file); | ||
// Buffers | ||
if(file.isBuffer()) { | ||
marked(String(file.contents), function (err, content) { | ||
if (!err) file.contents = Buffer(content); | ||
callback(err, file); | ||
}); | ||
// Streams | ||
} else { | ||
file.contents = file.contents.pipe(new BufferStreams(fileMarked())); | ||
callback(null, file); | ||
} | ||
}); | ||
}; | ||
}; | ||
// Export the file level transform function for other plugins usage | ||
gulpMarked.fileTransform = fileMarked; | ||
// Export the plugin main function | ||
module.exports = gulpMarked; | ||
{ | ||
"name": "gulp-marked", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Convert markdown to html with marked.", | ||
@@ -13,3 +13,4 @@ "keywords": [ | ||
"event-stream": "~3.0.15", | ||
"marked": "~0.2.10" | ||
"marked": "~0.2.10", | ||
"bufferstreams": "0.0.1" | ||
}, | ||
@@ -20,3 +21,3 @@ "scripts": { | ||
"devDependencies": { | ||
"gulp": "~2.6.0", | ||
"gulp": "~3.2.2", | ||
"mocha": "~1.15.1", | ||
@@ -30,2 +31,2 @@ "chai": "~1.8.1" | ||
] | ||
} | ||
} |
@@ -13,3 +13,3 @@ ## Information | ||
<td>Node Version</td> | ||
<td>≥ 0.6</td> | ||
<td>≥ 0.10</td> | ||
</tr> | ||
@@ -20,2 +20,4 @@ </table> | ||
In a Gulp task: | ||
```javascript | ||
@@ -33,2 +35,13 @@ var marked = require('gulp-marked'); | ||
In your own Gulp plugin: | ||
```js | ||
var markedTransform = require('gulp-marked').fileTransform; | ||
file.contents = file.contents.pipe(markerTransform(options)); | ||
// Then pipe you own contents in | ||
``` | ||
## LICENSE | ||
@@ -57,2 +70,2 @@ | ||
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -13,3 +13,4 @@ 'use strict'; | ||
describe('gulp-marked', function() { | ||
describe('in buffer mode', function() { | ||
it('should convert my files', function(done) { | ||
@@ -29,3 +30,32 @@ var filename = path.join(__dirname, './fixtures/data.md'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('gulp-marked markdown conversion', function() { | ||
describe('in stream mode', function() { | ||
it('should convert my files', function(done) { | ||
var filename = path.join(__dirname, './fixtures/data.md'); | ||
var markdown = fs.readFileSync(filename, { encoding: 'utf8' }); | ||
gulp.src(filename, {buffer: false}) | ||
.pipe(marked()) | ||
.pipe(es.map(function(file) { | ||
// Get the buffer to compare results | ||
file.contents.pipe(es.wait(function(err, data) { | ||
markedjs(markdown, function (err, content) { | ||
expect(data).to.equal(content); | ||
done(); | ||
}); | ||
})); | ||
})); | ||
}); | ||
}); | ||
}); |
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
5271
87
68
3
+ Addedbufferstreams@0.0.1
+ Addedbufferstreams@0.0.1(transitive)