npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markdown-to-restructuredtext

v2.0.1

Published

Convert Markdown to reStructuredText.

Downloads

82

Readme

Markdown to reStructuredText

NPM version Build Status Coverage Status Dependencies

Convert Markdown to reStructuredText.

Installation

$ npm install markdown-to-restructuredtext

Installation prerequisites:

Usage

var md2rst = require( 'markdown-to-restructuredtext' );

md2rst( [dest,] src[, opts], clbk )

Asynchronously converts a Markdown file to reStructuredText.

md2rst( './README.rst', './README.md', done );

function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'converted' );
}

The destination and source file paths may be either absolute or relative. If relative, a file path is resolved relative to the current working directory.

var inFile = '/path/to/my/file.md';
var outFile = './../output.rst';

process.chdir( '/some/directory' );

md2rst( outFile, inFile, done );

function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'output file: /some/output.rst' );
}

If not provided a destination file path, the function returns a reStructuredText string.

md2rst( './README.md', done );

function done( error, rst ) {
	if ( error ) {
		throw error;
	}
	console.log( rst );
}

The function accepts the following options:

  • flavor: Markdown flavor; e.g., 'github'. For supported flavors, see pandoc. Default: ''.

By default, the function assumes standard Markdown. To convert from a different Markdown flavor, set the flavor option.

var opts = {
	'flavor': 'github' // GFM
};

md2rst( './README.rst', './README.md', opts, done );

function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'converted from Github Flavored Markdown' );
}

md2rst.sync( [dest,] src[, opts] )

Synchronously converts a Markdown file to reStructuredText.

// Write to an output file:
md2rst.sync( './README.rst', './README.md' );

// Return a reStructuredText string:
var rst = md2rst.sync( './README.md' );
// returns <string>

The function accepts the same options as md2rst().

md2rst.fromString( [dest,] str[, opts], clbk )

Asynchronously converts a Markdown string to reStructuredText.

var readFile = require( 'utils-fs-read-file' ).sync;
var data = readFile( './README.md', {'encoding':'utf8'} );

md2rst.fromString( './README.rst', data, done );

function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'converted' );
}

If not provided a destination file path, the function returns a reStructuredText string.

md2rst.fromString( data, done );

function done( error, rst ) {
	if ( error ) {
		throw error;
	}
	console.log( rst );
}

The function accepts the same options as md2rst().

md2rst.fromStringSync( [dest,] str[, opts] )

Synchronously converts a Markdown string to reStructuredText.

var readFile = require( 'utils-fs-read-file' ).sync;
var data = readFile( './README.md', {'encoding':'utf8'} );

// Write to an output file:
md2rst.fromStringSync( './README.rst', data );

// Return a reStructuredText string:
var rst = md2rst.fromStringSync( data );
// returns <string>

The function accepts the same options as md2rst().

md2rst.fromBuffer( [dest,] buffer[, opts], clbk )

Asynchronously converts a Markdown buffer to reStructuredText.

var readFile = require( 'utils-fs-read-file' ).sync;
var data = readFile( './README.md' );

md2rst.fromBuffer( './README.rst', data, done );

function done( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'converted' );
}

If not provided a destination file path, the function returns a reStructuredText string.

md2rst.fromBuffer( data, done );

function done( error, rst ) {
	if ( error ) {
		throw error;
	}
	console.log( rst );
}

The function accepts the same options as md2rst().

md2rst.fromBufferSync( [dest,] buffer[, opts] )

Synchronously converts a Markdown buffer to reStructuredText.

var readFile = require( 'utils-fs-read-file' ).sync;
var data = readFile( './README.md' );

// Write to an output file:
md2rst.fromBufferSync( './README.rst', data );

// Return a reStructuredText string:
var rst = md2rst.fromBufferSync( data );
// returns <string>

The function accepts the same options as md2rst().


Examples

var path = require( 'path' );
var md2rst = require( 'markdown-to-restructuredtext' );

var inFile = path.resolve( __dirname, '../../README.md' );
var outFile = path.join( __dirname, './README.rst' );

var opts = {
	'flavor': 'github'
};

md2rst( inFile, opts, onResults );

function onResults( error, rst ) {
	if ( error ) {
		throw error;
	}
	console.log( rst );
}

md2rst( outFile, inFile, opts, onFile );

function onFile( error ) {
	if ( error ) {
		throw error;
	}
	console.log( 'Input file: %s', inFile );
	console.log( 'Output file: %s', outFile );
}

To run the example code from the top-level application directory,

$ DEBUG=* node ./examples/file_async/index.js

CLI

Installation

To use the module as a general utility, install the module globally

$ npm install -g markdown-to-restructuredtext

Usage

Usage: md2rst [options] inFile

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --flavor flavor      Markdown flavor. Default: (none).
  -o,  --output file        Output file path.

Notes

  • If not provided an output file path, the generated reStructuredText is written to stdout.

Examples

$ DEBUG=* md2rst --flavor=github -o ./README.rst ./README.md

For local installations, modify the command to point to the local installation directory; e.g.,

$ DEBUG=* ./node_modules/.bin/md2rst --flavor=github -o ./README.rst ./README.md

Or, if you have cloned this repository and run npm install, modify the command to point to the executable; e.g.,

$ DEBUG=* node ./bin/cli --flavor=github -o ./README.rst ./README.md

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2016. Athan Reines.