markdown-decorator

A lightweight utility for inserting blocks of text into markdown files.

OTHER License

Downloads
1
Stars
0
Committers
2

markdown-decorator

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![License][license-image]][license-url]

A lightweight utility for inserting text into markdown files and templates.

Table of contents

1. Installation

$ npm install --save markdown-decorator

2. Usage

2.1. Pass a markdown string to its constructor

const MarkdownDecorator = require('markdown-decorator')
const fs = require('fs')
const pkg = require('./package')

const decorator = new MarkdownDecorator(fs.readFileSync('README.md'))

2.2. Insert your product's (semantic) version

## Version and CHANGELOG

`markdown-decorator`'s latest version is
<!-- semver -->
<!-- semverend -->.
Please read the [CHANGELOG][changelog-url] for details.
// pkg.version === '1.1.0-alpha.1'
decorator.semver(pkg.version)

Inserts the semver:

## Version and CHANGELOG

`markdown-decorator`'s latest version is
<!-- semver -->1.1.0-alpha.1<!-- semverend -->.
Please read the [CHANGELOG][changelog-url] for details.

2.3. Generate a table of contents

Use toc comment tags as delimiters:

## Table of contents
<!-- toc -->
<!-- tocend -->
decorator.toc(markdown)

2.4. Method chaining

const md = decorator
  .semver(pkg.version)
  .toc(markdown)
  .toString()

2.5. Templates

<%= header %>
<%= body %>
---
<%= footer %>

Use the decorate method with an object literal to insert values in your template:

const md = decorator.decorate({
  version: '1.0.0'
})
.toString({
  template,
  header: '# TEMPLATE HEADER',
  body: decorator.markdown,
  footer: 'TEMPLATE FOOTER'
})

2.6. Insert a string between delimiters

# `<!-- title --><!-- titleend -->`
decorator.insert('markdown-decorator', {
	open: 'title',
	close: 'titleend'
})
decorator.markdown
// => # `<!-- title -->markdown-decorator<!-- titleend -->`

3. Version and CHANGELOG

markdown-decorator is at v1.0.0. Please see the CHANGELOG for details.

4. Contributing

[![PRs Welcome][makeapullrequest-image]][makeapullrequest-url] We welcome contributors and pull requests. Check out the guidelines for

Contributions are stories with a beginning, a middle, and an end, all told through issues, comments, commit logs, and pull requests.

  • [Peruse open issues][issues-url] or
  • [Open a new pull request (PR)][pr-url]

5. License

[![License][license-image]][license-url] Greg Swindle


[issues-url]: (https://github.com/gregswindle/markdown-decorator/issues [license-image]: https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat [license-url]: ./LICENSE [makeapullrequest-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square [makeapullrequest-url]: http://makeapullrequest.com [new-issue-url]: https://github.com/gregswindle/markdown-decorator/issues/new [npm-image]: https://badge.fury.io/js/markdown-decorator.svg [npm-url]: https://npmjs.org/package/markdown-decorator [pr-course-url]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github [pr-url]: https://github.com/gregswindle/markdown-decorator/pulls [pr-url]: https://github.com/gregswindle/markdown-decorator/pulls [standard-version-url]: https://github.com/conventional-changelog/standard-version [travis-image]: https://travis-ci.org/gregswindle/markdown-decorator.svg?branch=master [travis-url]: https://travis-ci.org/gregswindle/markdown-decorator

Package Rankings
Top 22.93% on Npmjs.org
Badges
Extracted from project README
Windows build status Dependency Status Codacy Badge Coverage percentage Greenkeeper badge