Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

md-writer

jbenner-radham49MIT1.1.0TypeScript support: included

A utility module for writing Markdown adhering to the CommonMark spec.

commonmark, markdown, md

readme

md-writer

CI Status

A utility module for writing Markdown adhering to the CommonMark spec.

Install

yarn add md-writer # Or alternatively: `npm install md-writer`

Usage

import {
    codeSpan,
    fencedCodeBlock,
    fencedJsCodeBlock,
    fencedShCodeBlock,
    fencedTsCodeBlock,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6
} from 'md-writer';

codeSpan('<span>Hello world!</span>');
// > `<span>Hello world!</span>`

fencedCodeBlock('5 + 5');
// >

// > 5 + 5 // > `

fencedCodeBlock(print('Hello world!'), 'python'); // > python // > print('Hello world!') // >

fencedJsCodeBlock('console.log("Hello world!");'); // > js // > console.log("Hello world!"); // >

fencedShCodeBlock(print 'Hello world!'); // > sh // > print 'Hello world!' // >

fencedTsCodeBlock('console.log("Hello world!");'); // > ts // > console.log("Hello world!"); // >

h1('Header One'); // > Header One // > ==========

h2('Header Two'); // > Header Two // > ----------

h3('Header Three'); // > ### Header Three

h4('Header Four'); // > #### Header Four

h5('Header Five'); // > ##### Header Five

h6('Header Six'); // > ###### Header Six


**NOTE**: This is a pure ESM package. See [here](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) for details.

Testing
-------
```sh
yarn test # Or alternatively: `npm test`

Reference

License

The MIT License (Expat). See the license file for details.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

1.1.0 - 2022-12-29

Added

  • Added TypeScript types.
  • Added h5() function.
  • Added h6() function.

Changed

  • Updated the "Usage" section of the README.md file.

1.0.0 - 2022-12-16

Added

  • Added h4() function.

Changed

  • Change over to ES Modules from CommonJS.
  • The MdWriter class no longer exists. Instead what used to be it's methods are now individual exports.
  • Updated the "Usage" section of the README.md file.
  • The minimum required Node.js is now v16.

0.3.0 - 2022-12-16

Added

  • Added MdWriter.fencedJsCodeBlock() method.
  • Added MdWriter.fencedTsCodeBlock() method.

Changed

  • The MdWriter.fencedShCodeBlock() method no longer prefixes the code with a dollar sign.

0.2.0 - 2017-09-30

Added

  • Added MdWriter.codeSpan() method.
  • Added MdWriter.h3() method.
  • Added "Reference" section to the README.md file.

Changed

  • Made the project description more specific in the readme and manifest.

0.1.0 - 2017-09-30

Added

  • Initial release.