Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multimarkdown table syntax plugin for markdown-it markdown parser

License

NotificationsYou must be signed in to change notification settings

redbug312/markdown-it-multimd-table

Repository files navigation

GitHub ActionNPM versionCoverage Status

MultiMarkdown table syntax plugin for markdown-it markdown parser

Intro

Markdown specs defines only the basics for tables. When users want commonfeatures likecolspan, they must fallback to raw HTML. And writing tables inHTML is trulylengthy and troublesome.

This plugin extends markdown-it with MultiMarkdown table syntax.MultiMarkdown is an extended Markdown spec. It defines clear rules foradvanced Markdown table syntax, while being consistent with original pipetable;markdown-it is a popular Markdown parser in JavaScript andallows plugins extending itself.

The features are provided:

  • Cell spans over columns
  • Cell spans over rows (optional)
  • Divide rows into sections
  • Multiple table headers
  • Table caption
  • Block-level elements such as lists, codes... (optional)
  • Omitted table header (optional)

Noted that the plugin is not a re-written of MultiMarkdown. This plugin willbehave differently from the official compiler, but doing its best to obey rulesdefined inMultiMarkdown User's Guide. Please pose an issue ifthere are weird results for sensible inputs.

Usage

// defaultsvarmd=require('markdown-it')().use(require('markdown-it-multimd-table'));// full options list (equivalent to defaults)varmd=require('markdown-it')().use(require('markdown-it-multimd-table'),{multiline:false,rowspan:false,headerless:false,multibody:true,autolabel:true,});md.render(/*...*/)

For a quick demo:

$mkdirmarkdown-it-multimd-table$cdmarkdown-it-multimd-table$npminstallmarkdown-itmarkdown-it-multimd-table--prefix.$vimtest.jsvarmd=require('markdown-it')().use(require('markdown-it-multimd-table'));constexampleTable="|             |          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));$nodetest.js>test.html$firefoxtest.html

Here's the table expected on browser:

Prototype table
Grouping
First HeaderSecond HeaderThird Header
ContentLong Cell
ContentCellCell
New sectionMoreData
And moreWith an escaped '|'

Noted that GitHub filters outstyle property, so the example usesalign theobsolete one. However it outputsstyle="text-align: ..." in actual.

Options

Multiline

Backslash at end merges with line content below.
Feature contributed byLucas-C.

|   Markdown| Rendered HTML||--------------|---------------||*Italic*  |*Italic*      |\||||    - Item 1  | - Item 1      |\|    - Item 2| - Item 2||```python |```python\|    .1 + .2   | .1 + .2\|    ```| ```|

This is parsed below when the option enabled:

MarkdownRendered HTML
*Italic*

Italic

- Item 1- Item 2
  • Item 1
  • Item 2
```python.1 + .2```
.1 + .2

Rowspan

^^ indicates cells being merged above.
Feature contributed bypmccloghrylaing.

Stage | Direct Products | ATP Yields----: | --------------: | ---------:Glycolysis | 2 ATP ||^^ | 2 NADH | 3--5 ATP |Pyruvaye oxidation | 2 NADH | 5 ATP |Citric acid cycle | 2 ATP ||^^ | 6 NADH | 15 ATP |^^ | 2 FADH2 | 3 ATP |**30--32** ATP |||[Net ATP yields per hexose]

This is parsed below when the option enabled:

Net ATP yields per hexose
StageDirect ProductsATP Yields
Glycolysis2 ATP
2 NADH3–5 ATP
Pyruvaye oxidation2 NADH5 ATP
Citric acid cycle2 ATP
6 NADH15 ATP
2 FADH23 ATP
30–32 ATP

Headerless

Table header can be eliminated.

|--|--|--|--|--|--|--|--|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

This is parsed below when the option enabled:

Multibody

An empty line separates consecutive table bodies. When disabled, an empty linealways cuts off the tables.

Autolabel

Tableid attribute follows the table caption if not labeled. When disabled,caption without labels cannot generate the attribute.

Credits

  • MultiMarkdown, Lightweightmarkup 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 theMIT license © RedBug312.

About

Multimarkdown table syntax plugin for markdown-it markdown parser

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp