Socket
Socket
Sign inDemoInstall

gulp-markdown-it-adapter

Package Overview
Dependencies
56
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gulp-markdown-it-adapter

An adapter for Gulp to render Markdown files with Markdown-It


Version published
Weekly downloads
55
increased by10%
Maintainers
1
Install size
760 kB
Created
Weekly downloads
 

Readme

Source

gulp-markdown-it-adapter

An adapter for Gulp to render Markdown files with Markdown-It.

It's not a wrapper, it's an adapter!
Why? I want to have full access to Markdown-It instance instead of place options to the wrapper.

This plugin is the same as gulp-markdown-it, but takes Markdown-It instance outside and written on pure JavaScript ES5.

Usage

Install as a development dependency:

npm install --save-dev gulp-markdown-it-adapter

Use in Gulpfile.js:

var gulp = require( 'gulp' );
var MarkdownIt = require( 'markdown-it' );
var gulpMarkdownIt = require( 'gulp-markdown-it-adapter' );
var highlightJs = require( 'highlight.js' );
var concat = require( 'gulp-concat' );
var mdToc = require( 'markdown-it-toc-and-anchor' ).default;
var wrap = require( 'gulp-wrap' );

gulp.task(
	'default',
	function ()
	{
		var sourcePath = './docs/*.md';
		var outputPath = './';
		var outputFileName = 'docs';
		var stylesPath = './styles';
		
		var optionsMd = {
			html: false,
			xhtmlOut: true,
			typographer: false,
			linkify: false,
			breaks: false,
			highlight: highlight
		};
		var optionsToc = {
			toc: true,
			tocFirstLevel: 2,
			tocLastLevel: 3,
			anchorLink: false,
			tocClassName: 'table-of-contents'
		};
		
		var md = new MarkdownIt( 'default', optionsMd );
		md.use( mdToc, optionsToc );
		
		return gulp.src( sourcePath )
			.pipe( concat( outputFileName + '.md' ) )
			.pipe( gulpMarkdownIt( md ) )
			.pipe( wrap( {src: stylesPath + '/template.html'} ) )
			.pipe( gulp.dest( outputPath ) );
	}
);

function highlight( str, lang )
{
	if ( lang && highlightJs.getLanguage( lang ) )
	{
		try
		{
			return highlightJs.highlight( lang, str ).value;
		}
		catch ( exception )
		{
			console.error( exception );
		}
	}
	
	try
	{
		return highlightJs.highlightAuto( str ).value;
	}
	catch ( exception )
	{
		console.error( exception );
	}
	
	return '';
}

License

MIT License ©

Keywords

FAQs

Last updated on 11 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc