{"name":"mdast-util-gfm-table","version":"0.1.6","description":"mdast extension to parse and serialize GFM tables","license":"MIT","keywords":["unist","mdast","mdast-util","util","utility","markdown","markup","table","row","column","cell","tabular","gfm"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/mdast-util-gfm-table.git"},"bugs":{"url":"https://github.com/syntax-tree/mdast-util-gfm-table/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"dependencies":{"markdown-table":"^2.0.0","mdast-util-to-markdown":"~0.6.0"},"devDependencies":{"mdast-util-from-markdown":"^0.8.0","micromark-extension-gfm-table":"^0.4.0","nyc":"^15.0.0","prettier":"^2.0.0","remark-cli":"^9.0.0","remark-preset-wooorm":"^8.0.0","string-width":"^4.0.0","tape":"^5.0.0","unist-util-remove-position":"^3.0.0","xo":"^0.37.0"},"scripts":{"format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test","test-coverage":"nyc --reporter lcov tape test.js","test":"npm run format && npm run test-coverage"},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"esnext":false,"rules":{"unicorn/prefer-includes":"off"}},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"704ed14ba30304e88b19250b2e3560665eeed3fa","homepage":"https://github.com/syntax-tree/mdast-util-gfm-table#readme","_id":"mdast-util-gfm-table@0.1.6","_nodeVersion":"15.1.0","_npmVersion":"6.14.10","dist":{"integrity":"sha512-j4yDxQ66AJSBwGkbpFEp9uG/LS1tZV3P33fN1gkyRB2LoRL+RR3f76m0HPHaby6F4Z5xr9Fv1URmATlRRUIpRQ==","shasum":"af05aeadc8e5ee004eeddfb324b2ad8c029b6ecf","tarball":"http://registry-npm.ywwl.com/mdast-util-gfm-table/download/mdast-util-gfm-table-0.1.6.tgz","fileCount":6,"unpackedSize":14291,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf8E8CCRA9TVsSAnZWagAA26AP/0sLiUnPOAhf3Vki+cG6\n2XK6nI1lInB0pVC5Zug/NeC4+4p6WVwoY9+2OMvgFxmKW6bG9MnHNzW8rEiT\nE2yaAWBxjKAFT/ZE+jjqI3JX+QOF52ppZE8xnMfGOx6aab1sX7F38U7oMJ5q\nSK6+qV1oIuF/4001lTgdYk8rd/CTbdjlULEIxfnmuCEhAclYFGl2Axcz1dCC\nKY+4dm+mE9VSCWldXh6BgedVccmUv+PVsID59Op0mtQv5DpNK5PgcVI5aI0/\nZpksPAIqGuEH6V+A6FW46Ix+LK6g3+Z8L8wnsW9L6DtNTluN+C8IQf3Ny+9g\nlvSkgoPejD0YtVW1IGDoCwvQ3GFhbKE+nxFeggmvuSKUOUUuBRlv1CeM4wbe\n6SsWFYILign1LkGilopzMyvEYrk5PrLboxirgBYo7n1swAqm1OiIayROgpui\n+kBzqzhVzwHt/Y8zzQvZTEOou7V6qFHMVuDV7ZvMJiOJ6gBKXFw36HN+Rygm\nvbzCR2JfM/cH5Nj0G++nr+zZSfMQjce7Eh2Qp28lpx19vXbjGMIHe2/uZxd/\noUIkOoNfChAYXuZUbdWHu833FDSjhO4BbK1TECovk6hBF6IKidy3XOqeJz2p\nBXSaMllkW1/CA4pMSo4TVX3/nfMBSflyJ+NWUCDKVx2jkegDiv8GmtkBP7cI\nlKvE\r\n=NljC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDMQfnNX+82ehrjzQIMwNRwaQXNvlIaS70SJE3I1g8eJgIgE1nPClO03gC9kJVYhY5PPY8FshZYKjg5dzZCAslOKmg="}],"size":5014,"noattachment":false,"key":"/mdast-util-gfm-table/-/mdast-util-gfm-table-0.1.6.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mdast-util-gfm-table_0.1.6_1609584386116_0.49707724991433566"},"_hasShrinkwrap":false,"readme":"# mdast-util-gfm-table\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[mdast][] extensions to parse and serialize [GFM][] tables.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When to use this](#when-to-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`gfmTableFromMarkdown`](#gfmtablefrommarkdown)\n    *   [`gfmTableToMarkdown(options?)`](#gfmtabletomarkdownoptions)\n    *   [`Options`](#options)\n*   [Examples](#examples)\n    *   [Example: `stringLength`](#example-stringlength)\n*   [HTML](#html)\n*   [Syntax](#syntax)\n*   [Syntax tree](#syntax-tree)\n    *   [Nodes](#nodes)\n    *   [Enumeration](#enumeration)\n    *   [Content model](#content-model)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package contains two extensions that add support for GFM table syntax in\nmarkdown to [mdast][].\nThese extensions plug into\n[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing\ntables in markdown into a syntax tree) and\n[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing\ntables in syntax trees to markdown).\n\n## When to use this\n\nYou can use these extensions when you are working with\n`mdast-util-from-markdown` and `mdast-util-to-markdown` already.\n\nWhen working with `mdast-util-from-markdown`, you must combine this package\nwith [`micromark-extension-gfm-table`][extension].\n\nWhen you don’t need a syntax tree, you can use [`micromark`][micromark]\ndirectly with `micromark-extension-gfm-table`.\n\nWhen you are working with syntax trees and want all of GFM, use\n[`mdast-util-gfm`][mdast-util-gfm] instead.\n\nAll these packages are used [`remark-gfm`][remark-gfm], which\nfocusses on making it easier to transform content by abstracting these\ninternals away.\n\nThis utility does not handle how markdown is turned to HTML.\nThat’s done by [`mdast-util-to-hast`][mdast-util-to-hast].\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-gfm-table\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {gfmTableFromMarkdown, gfmTableToMarkdown} from 'https://esm.sh/mdast-util-gfm-table@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'https://esm.sh/mdast-util-gfm-table@2?bundle'\n</script>\n```\n\n## Use\n\nSay our document `example.md` contains:\n\n```markdown\n| a | b | c | d |\n| - | :- | -: | :-: |\n| e | f |\n| g | h | i | j | k |\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport fs from 'node:fs/promises'\nimport {gfmTable} from 'micromark-extension-gfm-table'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table'\nimport {toMarkdown} from 'mdast-util-to-markdown'\n\nconst doc = await fs.readFile('example.md')\n\nconst tree = fromMarkdown(doc, {\n  extensions: [gfmTable()],\n  mdastExtensions: [gfmTableFromMarkdown()]\n})\n\nconsole.log(tree)\n\nconst out = toMarkdown(tree, {extensions: [gfmTableToMarkdown()]})\n\nconsole.log(out)\n```\n\n…now running `node example.js` yields (positional info removed for brevity):\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'table',\n      align: [null, 'left', 'right', 'center'],\n      children: [\n        {\n          type: 'tableRow',\n          children: [\n            {type: 'tableCell', children: [{type: 'text', value: 'a'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'b'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'c'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'd'}]}\n          ]\n        },\n        {\n          type: 'tableRow',\n          children: [\n            {type: 'tableCell', children: [{type: 'text', value: 'e'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'f'}]}\n          ]\n        },\n        {\n          type: 'tableRow',\n          children: [\n            {type: 'tableCell', children: [{type: 'text', value: 'g'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'h'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'i'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'j'}]},\n            {type: 'tableCell', children: [{type: 'text', value: 'k'}]}\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\n```markdown\n| a | b  |  c |  d  |   |\n| - | :- | -: | :-: | - |\n| e | f  |    |     |   |\n| g | h  |  i |  j  | k |\n```\n\n## API\n\nThis package exports the identifiers\n[`gfmTableFromMarkdown`][api-gfm-table-from-markdown] and\n[`gfmTableToMarkdown`][api-gfm-table-to-markdown].\nThere is no default export.\n\n### `gfmTableFromMarkdown`\n\nCreate an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]\nto enable GFM tables in markdown.\n\n###### Returns\n\nExtension for `mdast-util-from-markdown` to enable GFM tables\n([`FromMarkdownExtension`][from-markdown-extension]).\n\n### `gfmTableToMarkdown(options?)`\n\nCreate an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to\nenable GFM tables in markdown.\n\n###### Parameters\n\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nExtension for `mdast-util-to-markdown` to enable GFM tables\n([`ToMarkdownExtension`][to-markdown-extension]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `tableCellPadding` (`boolean`, default: `true`)\n    — whether to add a space of padding between delimiters and cells\n*   `tablePipeAlign` (`boolean`, default: `true`)\n    — whether to align the delimiters\n*   `stringLength` (`((value: string) => number)`, default: `s => s.length`)\n    — function to detect the length of table cell content, used when aligning\n    the delimiters between cells\n\n## Examples\n\n### Example: `stringLength`\n\nIt’s possible to align tables based on the visual width of cells.\nFirst, let’s show the problem:\n\n```js\nimport {gfmTable} from 'micromark-extension-gfm-table'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table'\nimport {toMarkdown} from 'mdast-util-to-markdown'\n\nconst doc = `| Alpha | Bravo |\n| - | - |\n| 中文 | Charlie |\n| 👩‍❤️‍👩 | Delta |`\n\nconst tree = fromMarkdown(doc, {\n  extensions: [gfmTable],\n  mdastExtensions: [gfmTableFromMarkdown]\n})\n\nconsole.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]}))\n```\n\nThe above code shows how these utilities can be used to format markdown.\nThe output is as follows:\n\n```markdown\n| Alpha    | Bravo   |\n| -------- | ------- |\n| 中文       | Charlie |\n| 👩‍❤️‍👩 | Delta   |\n```\n\nTo improve the alignment of these full-width characters and emoji, pass a\n`stringLength` function that calculates the visual width of cells.\nOne such algorithm is [`string-width`][string-width].\nIt can be used like so:\n\n```diff\n@@ -2,6 +2,7 @@ import {gfmTable} from 'micromark-extension-gfm-table'\n import {fromMarkdown} from 'mdast-util-from-markdown'\n import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table'\n import {toMarkdown} from 'mdast-util-to-markdown'\n+import stringWidth from 'string-width'\n\n const doc = `| Alpha | Bravo |\n | - | - |\n@@ -13,4 +14,8 @@ const tree = fromMarkdown(doc, {\n   mdastExtensions: [gfmTableFromMarkdown()]\n })\n\n-console.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]}))\n+console.log(\n+  toMarkdown(tree, {\n+    extensions: [gfmTableToMarkdown({stringLength: stringWidth})]\n+  })\n+)\n```\n\nThe output of our code with these changes is as follows:\n\n```markdown\n| Alpha | Bravo   |\n| ----- | ------- |\n| 中文  | Charlie |\n| 👩‍❤️‍👩    | Delta   |\n```\n\n## HTML\n\nThis utility does not handle how markdown is turned to HTML.\nThat’s done by [`mdast-util-to-hast`][mdast-util-to-hast].\n\n## Syntax\n\nSee [Syntax in `micromark-extension-gfm-table`][syntax].\n\n## Syntax tree\n\nThe following interfaces are added to **[mdast][]** by this utility.\n\n### Nodes\n\n#### `Table`\n\n```idl\ninterface Table <: Parent {\n  type: 'table'\n  align: [alignType]?\n  children: [TableContent]\n}\n```\n\n**Table** (**[Parent][dfn-parent]**) represents two-dimensional data.\n\n**Table** can be used where **[flow][dfn-flow-content]** content is expected.\nIts content model is **[table][dfn-table-content]** content.\n\nThe *[head][term-head]* of the node represents the labels of the columns.\n\nAn `align` field can be present.\nIf present, it must be a list of **[alignTypes][dfn-enum-align-type]**.\nIt represents how cells in columns are aligned.\n\nFor example, the following markdown:\n\n```markdown\n| foo | bar |\n| :-- | :-: |\n| baz | qux |\n```\n\nYields:\n\n```js\n{\n  type: 'table',\n  align: ['left', 'center'],\n  children: [\n    {\n      type: 'tableRow',\n      children: [\n        {\n          type: 'tableCell',\n          children: [{type: 'text', value: 'foo'}]\n        },\n        {\n          type: 'tableCell',\n          children: [{type: 'text', value: 'bar'}]\n        }\n      ]\n    },\n    {\n      type: 'tableRow',\n      children: [\n        {\n          type: 'tableCell',\n          children: [{type: 'text', value: 'baz'}]\n        },\n        {\n          type: 'tableCell',\n          children: [{type: 'text', value: 'qux'}]\n        }\n      ]\n    }\n  ]\n}\n```\n\n#### `TableRow`\n\n```idl\ninterface TableRow <: Parent {\n  type: \"tableRow\"\n  children: [RowContent]\n}\n```\n\n**TableRow** (**[Parent][dfn-parent]**) represents a row of cells in a table.\n\n**TableRow** can be used where **[table][dfn-table-content]** content is\nexpected.\nIts content model is **[row][dfn-row-content]** content.\n\nIf the node is a *[head][term-head]*, it represents the labels of the columns\nfor its parent **[Table][dfn-table]**.\n\nFor an example, see **[Table][dfn-table]**.\n\n#### `TableCell`\n\n```idl\ninterface TableCell <: Parent {\n  type: \"tableCell\"\n  children: [PhrasingContent]\n}\n```\n\n**TableCell** (**[Parent][dfn-parent]**) represents a header cell in a\n**[Table][dfn-table]**, if its parent is a *[head][term-head]*, or a data\ncell otherwise.\n\n**TableCell** can be used where **[row][dfn-row-content]** content is expected.\nIts content model is **[phrasing][dfn-phrasing-content]** content excluding\n**[Break][dfn-break]** nodes.\n\nFor an example, see **[Table][dfn-table]**.\n\n### Enumeration\n\n#### `alignType`\n\n```idl\nenum alignType {\n  'center' | 'left' | 'right' | null\n}\n```\n\n**alignType** represents how phrasing content is aligned\n([\\[CSSTEXT\\]][css-text]).\n\n*   **`'left'`**: See the [`left`][css-left] value of the `text-align` CSS\n    property\n*   **`'right'`**: See the [`right`][css-right] value of the `text-align`\n    CSS property\n*   **`'center'`**: See the [`center`][css-center] value of the `text-align`\n    CSS property\n*   **`null`**: phrasing content is aligned as defined by the host environment\n\n### Content model\n\n#### `FlowContent` (GFM table)\n\n```idl\ntype FlowContentGfm = Table | FlowContent\n```\n\n#### `TableContent`\n\n```idl\ntype TableContent = TableRow\n```\n\n**Table** content represent the rows in a table.\n\n#### `RowContent`\n\n```idl\ntype RowContent = TableCell\n```\n\n**Row** content represent the cells in a row.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Options`][api-options].\n\nThe `Table`, `TableRow`, and `TableCell` types of the mdast nodes are exposed\nfrom `@types/mdast`.\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `mdast-util-gfm-table@^2`,\ncompatible with Node.js 16.\n\nThis utility works with `mdast-util-from-markdown` version 2+ and\n`mdast-util-to-markdown` version 2+.\n\n## Related\n\n*   [`remarkjs/remark-gfm`][remark-gfm]\n    — remark plugin to support GFM\n*   [`syntax-tree/mdast-util-gfm`][mdast-util-gfm]\n    — same but all of GFM (autolink literals, footnotes, strikethrough, tables,\n    tasklists)\n*   [`micromark/micromark-extension-gfm-table`][extension]\n    — micromark extension to parse GFM tables\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-table/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-gfm-table/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-table.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-table\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-table.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-util-gfm-table\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-table\n\n[size]: https://bundlejs.com/?q=mdast-util-gfm-table\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[remark-gfm]: https://github.com/remarkjs/remark-gfm\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm\n\n[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown\n\n[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown\n\n[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast\n\n[micromark]: https://github.com/micromark/micromark\n\n[extension]: https://github.com/micromark/micromark-extension-gfm-table\n\n[syntax]: https://github.com/micromark/micromark-extension-gfm-table#syntax\n\n[gfm]: https://github.github.com/gfm/\n\n[string-width]: https://github.com/sindresorhus/string-width\n\n[css-text]: https://drafts.csswg.org/css-text/\n\n[css-left]: https://drafts.csswg.org/css-text/#valdef-text-align-left\n\n[css-right]: https://drafts.csswg.org/css-text/#valdef-text-align-right\n\n[css-center]: https://drafts.csswg.org/css-text/#valdef-text-align-center\n\n[term-head]: https://github.com/syntax-tree/unist#head\n\n[dfn-parent]: https://github.com/syntax-tree/mdast#parent\n\n[dfn-phrasing-content]: https://github.com/syntax-tree/mdast#phrasingcontent\n\n[dfn-break]: https://github.com/syntax-tree/mdast#break\n\n[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension\n\n[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options\n\n[api-gfm-table-from-markdown]: #gfmtablefrommarkdown\n\n[api-gfm-table-to-markdown]: #gfmtabletomarkdownoptions\n\n[api-options]: #options\n\n[dfn-flow-content]: #flowcontent-gfm-table\n\n[dfn-table-content]: #tablecontent\n\n[dfn-enum-align-type]: #aligntype\n\n[dfn-row-content]: #rowcontent\n\n[dfn-table]: #table\n","publish_time":1609584386326,"_cnpm_publish_time":1609584386326,"dist-tags":{"latest":"2.0.1"}}