Skip to content

4front/markdown-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Streaming markdown to html transformation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published