• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

wooorm/markdown-table: Generate a markdown (GFM) table

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

wooorm/markdown-table

开源软件地址(OpenSource Url):

https://github.com/wooorm/markdown-table

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

markdown-table

Build Coverage Downloads Size

Generate a markdown (GFM) table.

Contents

What is this?

This is a simple package that takes table data and generates a GitHub flavored markdown (GFM) table.

When should I use this?

You can use this package when you want to generate the source code of a GFM table from some data.

This is a simple solution in that it doesn’t handle escapes or HTML or any of that. For a complete but heavier solution, build an AST and serialize it with mdast-util-to-markdown (with mdast-util-gfm).

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install markdown-table

In Deno with esm.sh:

import {markdownTable} from 'https://esm.sh/markdown-table@3'

In browsers with esm.sh:

<script type="module">
  import {markdownTable} from 'https://esm.sh/markdown-table@3?bundle'
</script>

Use

Typical usage (defaults to align left):

import {markdownTable} from 'markdown-table'

markdownTable([
  ['Branch', 'Commit'],
  ['main', '0123456789abcdef'],
  ['staging', 'fedcba9876543210']
])

Yields:

| Branch  | Commit           |
| ------- | ---------------- |
| main    | 0123456789abcdef |
| staging | fedcba9876543210 |

With align:

markdownTable(
  [
    ['Beep', 'No.', 'Boop'],
    ['beep', '1024', 'xyz'],
    ['boop', '3388450', 'tuv'],
    ['foo', '10106', 'qrstuv'],
    ['bar', '45', 'lmno']
  ],
  {align: ['l', 'c', 'r']}
)

Yields:

| Beep |   No.   |   Boop |
| :--- | :-----: | -----: |
| beep |   1024  |    xyz |
| boop | 3388450 |    tuv |
| foo  |  10106  | qrstuv |
| bar  |    45   |   lmno |

API

This package exports the following identifiers: markdownTable. There is no default export.

markdownTable(table[, options])

Generate a markdown table from table data (matrix of strings).

options

Configuration (optional).

options.align

One style for all columns, or styles for their respective columns (string or Array<string>). Each style is either 'l' (left), 'r' (right), or 'c' (center). Other values are treated as '', which doesn’t place the colon in the alignment row but does align left. Only the lowercased first character is used, so Right is fine.

options.padding

Whether to add a space of padding between delimiters and cells (boolean, default: true).

When true, there is padding:

| Alpha | B     |
| ----- | ----- |
| C     | Delta |

When false, there is no padding:

|Alpha|B    |
|-----|-----|
|C    |Delta|
options.delimiterStart

Whether to begin each row with the delimiter (boolean, default: true).


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap