Nutrias Punching Marmots

    markdown2code

    1.0.2 • Public • Published

    markdown2code

    extracts code blocks (surrounded by triple backticks) from markdown

    Installation | API | CLI | License

    JavaScript Style Guide

    Installation

    With npm do

    npm install markdown2code
    

    Then, if you add a script to your package.json, like the following one

        "markdown2code""markdown2code -l javascript README.md > ${npm_package_main}",

    you can do literate programming in your README.md and extract code running

    npm run markdown2code

    See also CLI Usage and Example sections.

    CLI

    Usage

    markdown2code [--lang <language>] file.md
    

    Options

    • -l --lang language filter
    • -h --help shows this text message
    • -v --version prints package version

    Example

    Suppose you have JavaScript code in your README.md, enclosed by triple backticks and with javascript keyword to enable code highlighiting, for example

    ```javascript
    var a = 1
    ```
    

    Extract all javascript snippets with command

    markdown2code --lang javascript README.md
    

    which will stream to STDOUT the following code

    var a = 1
    

    Note that you can still use the js keyword to document example snippets, i.e. the following markdown will be ignored, if markdown2code is launched with option --lang javascript

    ```js
    // This highlighted JavaScript code will be ignored.
    console.log(a)
    ```
    

    API

    The markdown2code function accepts the following parameters.

    • @param {Stream} input
    • @param {Stream} output
    • @param {Object} [opt]
    • @param {String} [opt.lang] filter

    For example:

    const markdown2code = require('markdown2code')
     
    const fs = require('fs')
    const input = fs.createReadStream('README.md')
    const output = process.stdout
     
    markdown2code(input, output)

    License

    MIT

    Install

    npm i markdown2code

    DownloadsWeekly Downloads

    0

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    6.16 kB

    Total Files

    8

    Last publish

    Collaborators

    • fibo