Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micromark-extension-gfm-table

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-gfm-table - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

68

dev/lib/html.js
/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/
/**
* @typedef {import('./syntax.js').Align} Align

@@ -10,3 +7,3 @@ */

const alignment = {
null: '',
none: '',
left: ' align="left"',

@@ -21,6 +18,8 @@ right: ' align="right"',

table(token) {
/** @type {Array<Align>} */
// @ts-expect-error Custom.
const tableAlign = token._align
this.lineEndingIfNeeded()
this.tag('<table>')
// @ts-expect-error Custom.
this.setData('tableAlign', token._align)
this.setData('tableAlign', tableAlign)
},

@@ -33,6 +32,7 @@ tableBody() {

tableData() {
/** @type {string|undefined} */
const align =
// @ts-expect-error Custom.
alignment[this.getData('tableAlign')[this.getData('tableColumn')]]
const tableAlign = /** @type {Array<Align>} */ (
this.getData('tableAlign')
)
const tableColumn = /** @type {number} */ (this.getData('tableColumn'))
const align = alignment[tableAlign[tableColumn]]

@@ -52,9 +52,10 @@ if (align === undefined) {

tableHeader() {
const tableAlign = /** @type {Array<Align>} */ (
this.getData('tableAlign')
)
const tableColumn = /** @type {number} */ (this.getData('tableColumn'))
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag(
'<th' +
// @ts-expect-error Custom.
alignment[this.getData('tableAlign')[this.getData('tableColumn')]] +
'>'
)
this.tag('<th' + align + '>')
},

@@ -92,10 +93,10 @@ tableRow() {

tableData() {
/** @type {number} */
// @ts-expect-error Custom.
const column = this.getData('tableColumn')
const tableAlign = /** @type {Array<Align>} */ (
this.getData('tableAlign')
)
const tableColumn = /** @type {number} */ (this.getData('tableColumn'))
// @ts-expect-error Custom.
if (column in this.getData('tableAlign')) {
if (tableColumn in tableAlign) {
this.tag('</td>')
this.setData('tableColumn', column + 1)
this.setData('tableColumn', tableColumn + 1)
} else {

@@ -113,22 +114,19 @@ // Stop capturing.

tableHeader() {
const tableColumn = /** @type {number} */ (this.getData('tableColumn'))
this.tag('</th>')
// @ts-expect-error Custom.
this.setData('tableColumn', this.getData('tableColumn') + 1)
this.setData('tableColumn', tableColumn + 1)
},
tableRow() {
/** @type {Align[]} */
// @ts-expect-error Custom.
const align = this.getData('tableAlign')
/** @type {number} */
// @ts-expect-error Custom.
let column = this.getData('tableColumn')
const tableAlign = /** @type {Array<Align>} */ (
this.getData('tableAlign')
)
let tableColumn = /** @type {number} */ (this.getData('tableColumn'))
while (column < align.length) {
while (tableColumn < tableAlign.length) {
this.lineEndingIfNeeded()
// @ts-expect-error `null` is fine as an index.
this.tag('<td' + alignment[align[column]] + '></td>')
column++
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
}
this.setData('tableColumn', column)
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()

@@ -135,0 +133,0 @@ this.tag('</tr>')

@@ -8,2 +8,2 @@ /** @type {Extension} */

export type Token = import('micromark-util-types').Token
export type Align = 'left' | 'center' | 'right' | null
export type Align = 'left' | 'center' | 'right' | 'none'

@@ -10,3 +10,3 @@ /**

/**
* @typedef {'left'|'center'|'right'|null} Align
* @typedef {'left'|'center'|'right'|'none'} Align
*/

@@ -163,3 +163,3 @@

const self = this
/** @type {Align[]} */
/** @type {Array<Align>} */
const align = []

@@ -310,3 +310,3 @@ let tableHeaderCount = 0

hasDash = true
align.push(null)
align.push('none')
return inFillerDelimiter

@@ -313,0 +313,0 @@ }

/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/
/**
* @typedef {import('./syntax.js').Align} Align
*/
const alignment = {
null: '',
none: '',
left: ' align="left"',

@@ -19,6 +16,8 @@ right: ' align="right"',

table(token) {
/** @type {Array<Align>} */
// @ts-expect-error Custom.
const tableAlign = token._align
this.lineEndingIfNeeded()
this.tag('<table>') // @ts-expect-error Custom.
this.setData('tableAlign', token._align)
this.tag('<table>')
this.setData('tableAlign', tableAlign)
},

@@ -33,5 +32,9 @@

tableData() {
/** @type {string|undefined} */
const align = // @ts-expect-error Custom.
alignment[this.getData('tableAlign')[this.getData('tableColumn')]]
const tableAlign =
/** @type {Array<Align>} */
this.getData('tableAlign')
const tableColumn =
/** @type {number} */
this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]

@@ -53,8 +56,11 @@ if (align === undefined) {

tableHeader() {
const tableAlign =
/** @type {Array<Align>} */
this.getData('tableAlign')
const tableColumn =
/** @type {number} */
this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag(
'<th' + // @ts-expect-error Custom.
alignment[this.getData('tableAlign')[this.getData('tableColumn')]] +
'>'
)
this.tag('<th' + align + '>')
},

@@ -96,9 +102,12 @@

tableData() {
/** @type {number} */
// @ts-expect-error Custom.
const column = this.getData('tableColumn') // @ts-expect-error Custom.
const tableAlign =
/** @type {Array<Align>} */
this.getData('tableAlign')
const tableColumn =
/** @type {number} */
this.getData('tableColumn')
if (column in this.getData('tableAlign')) {
if (tableColumn in tableAlign) {
this.tag('</td>')
this.setData('tableColumn', column + 1)
this.setData('tableColumn', tableColumn + 1)
} else {

@@ -117,24 +126,24 @@ // Stop capturing.

tableHeader() {
this.tag('</th>') // @ts-expect-error Custom.
this.setData('tableColumn', this.getData('tableColumn') + 1)
const tableColumn =
/** @type {number} */
this.getData('tableColumn')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
},
tableRow() {
/** @type {Align[]} */
// @ts-expect-error Custom.
const align = this.getData('tableAlign')
/** @type {number} */
// @ts-expect-error Custom.
const tableAlign =
/** @type {Array<Align>} */
this.getData('tableAlign')
let tableColumn =
/** @type {number} */
this.getData('tableColumn')
let column = this.getData('tableColumn')
while (column < align.length) {
this.lineEndingIfNeeded() // @ts-expect-error `null` is fine as an index.
this.tag('<td' + alignment[align[column]] + '></td>')
column++
while (tableColumn < tableAlign.length) {
this.lineEndingIfNeeded()
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
}
this.setData('tableColumn', column)
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()

@@ -141,0 +150,0 @@ this.tag('</tr>')

@@ -8,2 +8,2 @@ /** @type {Extension} */

export type Token = import('micromark-util-types').Token
export type Align = 'left' | 'center' | 'right' | null
export type Align = 'left' | 'center' | 'right' | 'none'

@@ -10,3 +10,3 @@ /**

/**
* @typedef {'left'|'center'|'right'|null} Align
* @typedef {'left'|'center'|'right'|'none'} Align
*/

@@ -159,3 +159,3 @@ import {factorySpace} from 'micromark-factory-space'

const self = this
/** @type {Align[]} */
/** @type {Array<Align>} */

@@ -299,3 +299,3 @@ const align = []

hasDash = true
align.push(null)
align.push('none')
return inFillerDelimiter

@@ -302,0 +302,0 @@ }

{
"name": "micromark-extension-gfm-table",
"version": "1.0.4",
"version": "1.0.5",
"description": "micromark extension to support GFM tables",

@@ -52,2 +52,3 @@ "license": "MIT",

"c8": "^7.0.0",
"create-gfm-fixtures": "^1.0.0",
"micromark": "^3.0.0",

@@ -62,3 +63,3 @@ "micromark-build": "^1.0.0",

"typescript": "^4.0.0",
"xo": "^0.46.0"
"xo": "^0.47.0"
},

@@ -65,0 +66,0 @@ "scripts": {

@@ -13,17 +13,43 @@ # micromark-extension-gfm-table

[tables][].
This syntax extension matches the GFM spec and github.com.
## Contents
* [What is this?](#what-is-this)
* [When to use this](#when-to-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`gfmTable`](#gfmtable)
* [`gfmTableHtml`](#gfmtablehtml)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a micromark extension to add support for GFM tables.
It matches how tables work on `github.com`.
## When to use this
You should probably use [`micromark-extension-gfm`][micromark-extension-gfm]
instead, which combines this package with other GFM features.
Alternatively, if you don’t want all of GFM, use this package.
In many cases, when working with micromark, you’d want to use
[`micromark-extension-gfm`][micromark-extension-gfm] instead, which combines
this package with other GFM features.
When working with syntax trees, you’d want to combine this package with
[`mdast-util-gfm-table`][mdast-util-gfm-table] (or
[`mdast-util-gfm`][mdast-util-gfm] when using `micromark-extension-gfm`).
These tools are all rather low-level.
In most cases, you’d instead want to use [`remark-gfm`][remark-gfm] with
[remark][].
## Install
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
[npm][]:
```sh

@@ -33,2 +59,16 @@ npm install micromark-extension-gfm-table

In Deno with [Skypack][]:
```js
import {gfmTable, gfmTableHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm-table@1?dts'
```
In browsers with [Skypack][]:
```html
<script type="module">
import {gfmTable, gfmTableHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm-table@1?min'
</script>
```
## Use

@@ -72,26 +112,31 @@

An extension for micromark to parse GFM tables (can be passed in `extensions`).
### `gfmTableHtml`
An extension for micromark to parse tables (can be passed in
`extensions`) and one to compile to `<table>` elements (can be passed in
`htmlExtensions`).
An extension to compile them to HTML (can be passed in `htmlExtensions`).
## Types
This package is fully typed with [TypeScript][].
There are no additional exported types.
## Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.
## Security
This package is safe.
## Related
* [`remarkjs/remark`][remark]
— markdown processor powered by plugins
* [`remarkjs/remark-gfm`](https://github.com/remarkjs/remark-gfm)
— remark plugin using this and other GFM features
* [`micromark/micromark`][micromark]
— the smallest commonmark-compliant markdown parser that exists
* [`micromark/micromark-extension-gfm`][micromark-extension-gfm]
— micromark extension combining this with other GFM features
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
— mdast utility to support tables
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm)
— mdast utility to support GFM
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
— mdast parser using `micromark` to create mdast from markdown
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
— mdast serializer to create markdown from mdast
* [`syntax-tree/mdast-util-gfm-table`][mdast-util-gfm-table]
— support GFM tables in mdast
* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm]
— support GFM in mdast
* [`remarkjs/remark-gfm`][remark-gfm]
— support GFM in remark

@@ -142,2 +187,4 @@ ## Contribute

[skypack]: https://www.skypack.dev
[license]: license

@@ -147,18 +194,24 @@

[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[micromark]: https://github.com/micromark/micromark
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
[typescript]: https://www.typescriptlang.org
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
[micromark]: https://github.com/micromark/micromark
[remark]: https://github.com/remarkjs/remark
[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm
[mdast-util-gfm-table]: https://github.com/syntax-tree/mdast-util-gfm-table
[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm
[remark-gfm]: https://github.com/remarkjs/remark-gfm
[tables]: https://github.github.com/gfm/#tables-extension-
[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc