Giter Site home page Giter Site logo

pmccloghrylaing / markdown-it-multimd-table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redbug312/markdown-it-multimd-table

0.0 1.0 0.0 92 KB

Multimarkdown table syntax plugin for markdown-it markdown parser

License: MIT License

Makefile 9.78% JavaScript 90.22%

markdown-it-multimd-table's Introduction

NPM version Build Status Coverage Status

MultiMarkdown table syntax plugin for markdown-it markdown parser

Intro

In general Markdown syntax, we have to write raw HTML tags when colspan attribute is needed. Luckily, I found that MultiMarkdown had defined complete and clear rules for advanced Markdown table syntax, and compatible to general Markdown table syntax.

So I extend the table parser in markdown-it to support MultiMarkdown table syntax. For now, the following features are provided:

  • Cells spanning multiple columns
  • Grouped table headers
  • Grouped table rows
  • Table captions
  • Lists in table cell (optional)
  • Line breaks in table cells (optional)

Noted that the plugin might behave differently from MultiMarkdown in some edge cases; since the plugin aims just to follow the rules in MultiMarkdown User's Guide.

Usage

var md = require('markdown-it')()
            .use(require('markdown-it-multimd-table'));

md.render(/*...*/)

To simply test this plugin, you can do these in terminal:

$ mkdir markdown-it-multimd-table
$ cd markdown-it-multimd-table
$ npm install markdown-it-multimd-table --prefix .
$ vim test.js

    var md = require('markdown-it')()
                .use(require('markdown-it-multimd-table'));

    const exampleTable =
    "|             |          Grouping           || \n" +
    "First Header  | Second Header | Third Header | \n" +
    " ------------ | :-----------: | -----------: | \n" +
    "Content       |          *Long Cell*        || \n" +
    "Content       |   **Cell**    |         Cell | \n" +
    "                                               \n" +
    "New section   |     More      |         Data | \n" +
    "And more      | With an escaped '\\|'       || \n" +
    "[Prototype table]                              \n";

    console.log(md.render(exampleTable));

$ node test.js > test.html
$ firefox test.html

And you will see the rendered table in the browser:

Prototype table
Grouping
First Header Second Header Third Header
Content Long Cell
Content Cell Cell
New section More Data
And more With an escaped '|'

Multiple lines of row (optional)

Put backslashes at end to make the table rows parsed as multiple lines. This feature is contributed by Lucas-C.

First header | Second header
-------------|---------------
List:        | More  \
- over       | data  \
- several    |       \
- lines      |

would be parsed as

First header Second header

List:

  • over
  • several
  • lines

More data

And here's how you enable the feature.

var md = require('markdown-it')()
            .use(require('markdown-it-multimd-table'), {enableMultilineRows: true});

Credits

  • MultiMarkdown, Lightweight markup processor to produce HTML, LaTeX, and more.
  • markdown-it, Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed.

License

This software is licensed under the MIT license © RedBug312.

markdown-it-multimd-table's People

Contributors

redbug312 avatar jf0772256 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.