markdown-transform
v1.0.1
Published
Markdown transform stream
Downloads
13
Readme
markdown-transform
Light streaming wrapper around the marked markdown parser. Useful for passing to APIs that expect a stream compliant interface. Note that marked itself does not support streams so the entire markdown string is buffered in memory.
Installation
npm install markdown-transform
Options
Supports passthrough of all the marked options. As a shorthand, rather than passing a function to the highlight
option, you can simply pass true
which will perform syntax highlighting with highlight.js.
Usage
var markdownTransform = require('markdown-transform');
fs.createReadStream('README.md')
.pipe(markdownTransform({highlight: true}))
.pipe(process.stdout);
Express middleware
app.get('/readme', function(req, res, next) {
var transform = markdownTransform({highlight: true});
res.set('Content-Type', transform.contentType);
fs.createReadStream('./markdown.md')
.pipe(transform)
.pipe(res);
});
Express Api Proxy
Works seamlessly for transforming Markdown API responses to HTML with the express-api-proxy.
// Express app
app.all('/proxy', require('express-api-proxy')({
endpoints: [
{
pattern: /raw\.githubusercontent\.com\/.*\.md/,
transform: require('markdown-transform')({highlight:true})
}
]
}));
// Browser app
$.ajax({
url: '/proxy',
data: {
url: 'https://raw.githubusercontent.com/4front/express-api-proxy/master/README.md'
},
success: function(data) {
$('#readme').html(data);
}
});