{"_id":"mdast-util-gfm-table@2.0.1","bugs":{"url":"https://github.com/syntax-tree/mdast-util-gfm-table/issues"},"dist":{"shasum":"e3e458c17ec07c5680d68688cb95764089a63efd","tarball":"http://registry-npm.ywwl.com/mdast-util-gfm-table/download/mdast-util-gfm-table-2.0.1.tgz","fileCount":8,"integrity":"sha512-fiIjPrAy4kz68/eFbPHhsiWDGHhqUSVoU1XsfLM5DsEPXw7MxgiVVyulUggFRckVWeT1KXQXkg5vm3kv4oMSOA==","signatures":[{"sig":"MEQCIC9GAnOwp7VD5+qYvan4675DY5hQxPgE+D8iJjdzc1ITAiBOUz4lZeN6SauyUdH9xqL8l2ziEkU5QI3JyAyd0uJ87A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD5FmSAxnyV6u0otCmOWCYUgXShmBnQtCkN5aFzgxLnjQIhAOGuQM3tcHpKzVLPDoklNY1bQ/WDWqFmgtDQRKEiV+VK"}],"unpackedSize":33805,"size":9899,"noattachment":false,"key":"/mdast-util-gfm-table/-/mdast-util-gfm-table-2.0.1.tgz"},"name":"mdast-util-gfm-table","type":"module","types":"./index.d.ts","author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"35b52322b4553bd2d3258f0b415a1fe0e3cfa92e","license":"MIT","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix","prepack":"npm run build && npm run format","test-api":"npm run test-api-dev && npm run test-api-prod","test-api-dev":"node --conditions development test.js","test-api-prod":"node --conditions production test.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api"},"version":"2.0.1","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"homepage":"https://github.com/syntax-tree/mdast-util-gfm-table#readme","keywords":["cell","column","gfm","markdown","markup","mdast-util","mdast","row","table","tabular","unist","utility","util"],"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/mdast-util-gfm-table.git","type":"git"},"_npmVersion":"12.2.1","description":"mdast extension to parse and serialize GFM tables","directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"sideEffects":false,"_nodeVersion":"26.12.1","contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"dependencies":{"devlop":"^1.0.0","@types/mdast":"^4.0.0","markdown-table":"^3.0.0","unist-util-visit":"^5.0.0","mdast-util-to-string":"^4.0.0","mdast-util-to-markdown":"^2.0.0","mdast-util-from-markdown":"^2.0.0"},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"strict":true,"atLeast":100},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","xo":"^5.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^6.0.0","@types/node":"^26.0.0","string-width":"^8.0.0","type-coverage":"^2.0.0","remark-preset-wooorm":"^11.0.0","unist-util-remove-position":"^5.0.0","micromark-extension-gfm-table":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mdast-util-gfm-table_2.0.1_1793736309268_0.2413672477322244"},"readme":"# mdast-util-gfm-table\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n[![Size][badge-size-image]][badge-size-url]\n\n[mdast][github-mdast] extensions to parse and serialize [GFM][spec-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][github-mdast].\nThese extensions plug into\n[`mdast-util-from-markdown`][github-mdast-util-from-markdown]\n(to support parsing tables in markdown into a syntax tree) and\n[`mdast-util-to-markdown`][github-mdast-util-to-markdown]\n(to support serializing tables 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`][github-micromark-extension-gfm-table].\n\nWhen you don’t need a syntax tree, you can use [`micromark`][github-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`][github-mdast-util-gfm] instead.\n\nAll these packages are used in [`remark-gfm`][github-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`][github-mdast-util-to-hast].\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+), install with [npm][npmjs-install]:\n\n```sh\nnpm install mdast-util-gfm-table\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\n[`mdast-util-from-markdown`][github-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`][github-mdast-util-from-markdown-extension]).\n\n### `gfmTableToMarkdown(options?)`\n\nCreate an extension for\n[`mdast-util-to-markdown`][github-mdast-util-to-markdown]\nto enable 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`][github-mdast-util-to-markdown-options]).\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`][github-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`][github-mdast-util-to-hast].\n\n## Syntax\n\nSee [Syntax in\n`micromark-extension-gfm-table`][github-micromark-extension-gfm-table-syntax].\n\n## Syntax tree\n\nThe following interfaces are added to **[mdast][github-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][github-mdast-parent]**) represents two-dimensional data.\n\n**Table** can be used where **[flow][api-flow-content]** content is expected.\nIts content model is **[table][api-table-content]** content.\n\nThe *[head][github-unist-head]* of the node represents the labels of the\ncolumns.\n\nAn `align` field can be present.\nIf present, it must be a list of **[alignTypes][api-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][github-mdast-parent]**) represents a row of cells in\na table.\n\n**TableRow** can be used where **[table][api-table-content]** content is\nexpected.\nIts content model is **[row][api-row-content]** content.\n\nIf the node is a *[head][github-unist-head]*,\nit represents the labels of the columns for its parent **[Table][api-table]**.\n\nFor an example, see **[Table][api-table]**.\n\n#### `TableCell`\n\n```idl\ninterface TableCell <: Parent {\n  type: \"tableCell\"\n  children: [PhrasingContent]\n}\n```\n\n**TableCell** (**[Parent][github-mdast-parent]**) represents a header cell in\na **[Table][api-table]**, if its parent is a *[head][github-unist-head]*,\nor a data cell otherwise.\n\n**TableCell** can be used where **[row][api-row-content]** content is expected.\nIts content model is **[phrasing][github-mdast-phrasing-content]** content\nexcluding **[Break][github-mdast-break]** nodes.\n\nFor an example, see **[Table][api-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\\]][spec-css-text]).\n\n* **`'left'`**: See the [`left`][spec-css-text-align-left] value of the\n  `text-align` CSS property\n* **`'right'`**: See the [`right`][spec-css-text-align-right] value of the\n  `text-align` CSS property\n* **`'center'`**: See the [`center`][spec-css-text-align-center] value of\n  the `text-align` 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* [`remark-gfm`][github-remark-gfm]\n  — remark plugin to support GFM\n* [`mdast-util-gfm`][github-mdast-util-gfm]\n  — same but all of GFM (autolink literals, footnotes, strikethrough, tables,\n  tasklists)\n* [`micromark-extension-gfm-table`][github-micromark-extension-gfm-table]\n  — micromark extension to parse GFM tables\n\n## Contribute\n\nSee [`contributing.md`][health-contributing] in\n[`syntax-tree/.github`][health] for ways to get started.\nSee [`support.md`][health-support] for ways to get help.\n\nThis project has a [code of conduct][health-coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][file-license] © [Titus Wormer][wooorm]\n\n<!-- Definitions -->\n\n[api-align-type]: #aligntype\n\n[api-flow-content]: #flowcontent-gfm-table\n\n[api-gfm-table-from-markdown]: #gfmtablefrommarkdown\n\n[api-gfm-table-to-markdown]: #gfmtabletomarkdownoptions\n\n[api-options]: #options\n\n[api-row-content]: #rowcontent\n\n[api-table]: #table\n\n[api-table-content]: #tablecontent\n\n[badge-build-image]: https://github.com/syntax-tree/mdast-util-gfm-table/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/syntax-tree/mdast-util-gfm-table/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-table.svg\n\n[badge-coverage-url]: https://codecov.io/github/syntax-tree/mdast-util-gfm-table\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/mdast-util-gfm-table.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/mdast-util-gfm-table\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/mdast-util-gfm-table\n\n[badge-size-url]: https://bundlejs.com/?q=mdast-util-gfm-table\n\n[esmsh]: https://esm.sh\n\n[file-license]: license\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-mdast]: https://github.com/syntax-tree/mdast\n\n[github-mdast-break]: https://github.com/syntax-tree/mdast#break\n\n[github-mdast-parent]: https://github.com/syntax-tree/mdast#parent\n\n[github-mdast-phrasing-content]: https://github.com/syntax-tree/mdast#phrasingcontent\n\n[github-mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown\n\n[github-mdast-util-from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension\n\n[github-mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm\n\n[github-mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast\n\n[github-mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown\n\n[github-mdast-util-to-markdown-options]: https://github.com/syntax-tree/mdast-util-to-markdown#options\n\n[github-micromark]: https://github.com/micromark/micromark\n\n[github-micromark-extension-gfm-table]: https://github.com/micromark/micromark-extension-gfm-table\n\n[github-micromark-extension-gfm-table-syntax]: https://github.com/micromark/micromark-extension-gfm-table#syntax\n\n[github-remark-gfm]: https://github.com/remarkjs/remark-gfm\n\n[github-string-width]: https://github.com/sindresorhus/string-width\n\n[github-unist-head]: https://github.com/syntax-tree/unist#head\n\n[health]: https://github.com/syntax-tree/.github\n\n[health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[health-support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[npmjs-install]: https://docs.npmjs.com/cli/install\n\n[spec-css-text]: https://drafts.csswg.org/css-text/\n\n[spec-css-text-align-center]: https://drafts.csswg.org/css-text/#valdef-text-align-center\n\n[spec-css-text-align-left]: https://drafts.csswg.org/css-text/#valdef-text-align-left\n\n[spec-css-text-align-right]: https://drafts.csswg.org/css-text/#valdef-text-align-right\n\n[spec-gfm]: https://github.github.com/gfm/\n\n[typescript]: https://www.typescriptlang.org\n\n[wooorm]: https://wooorm.com\n","publish_time":1793736309360,"_cnpm_publish_time":1793736309360,"dist-tags":{"latest":"2.0.1"}}