markdown-transform

1.0.1 • Public • Published

markdown-transform

NPM Version NPM Downloads Build Status Test Coverage

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);
    }
});

Package Sidebar

Install

npm i markdown-transform

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • dvonlehman