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.7 to 2.0.0

3

dev/index.d.ts

@@ -7,3 +7,2 @@ import type {Align} from './lib/infer.js'

declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Token {

@@ -13,3 +12,2 @@ _align?: Align[]

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface TokenTypeMap {

@@ -30,3 +28,2 @@ table: 'table'

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CompileData {

@@ -33,0 +30,0 @@ tableAlign?: Align[]

8

dev/lib/edit-map.d.ts

@@ -24,3 +24,3 @@ /**

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -31,3 +31,3 @@ add(

add: Array<import('micromark-util-types').Event>
): void
): undefined
/**

@@ -37,5 +37,5 @@ * Done, change the events.

* @param {Array<Event>} events
* @returns {void}
* @returns {undefined}
*/
consume(events: Array<import('micromark-util-types').Event>): void
consume(events: Array<import('micromark-util-types').Event>): undefined
}

@@ -42,0 +42,0 @@ export type Event = import('micromark-util-types').Event

@@ -45,3 +45,3 @@ /**

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -52,3 +52,3 @@ add(index, remove, add) {

// To do: not used here.
// To do: add this when moving to `micromark`.
// /**

@@ -60,3 +60,3 @@ // * Create an edit: but insert `add` before existing additions.

// * @param {Array<Event>} add
// * @returns {void}
// * @returns {undefined}
// */

@@ -71,6 +71,8 @@ // addBefore(index, remove, add) {

* @param {Array<Event>} events
* @returns {void}
* @returns {undefined}
*/
consume(events) {
this.map.sort((a, b) => a[0] - b[0])
this.map.sort(function (a, b) {
return a[0] - b[0]
})

@@ -105,5 +107,6 @@ /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */

index -= 1
vecs.push(events.slice(this.map[index][0] + this.map[index][1]))
// eslint-disable-next-line unicorn/no-array-push-push
vecs.push(this.map[index][2])
vecs.push(
events.slice(this.map[index][0] + this.map[index][1]),
this.map[index][2]
)

@@ -136,3 +139,3 @@ // Truncate rest.

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -151,3 +154,3 @@ function addImpl(editMap, at, remove, add) {

// To do: before not used.
// To do: before not used by tables, use when moving to micromark.
// if (before) {

@@ -196,3 +199,2 @@ // add.push(...editMap.map[index][2])

// } else {
// console.log('to do: links?', add, rmCurr)
// // ?

@@ -199,0 +201,0 @@ // // if let Some(link) = &events[index].link {

/**
* Extension for `micromark` that can be passed in `htmlExtensions` to support
* GFM tables when serializing to HTML.
* Create an HTML extension for `micromark` to support GitHub tables when
* serializing to HTML.
*
* @type {HtmlExtension}
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GitHub tables when serializing to HTML.
*/
export const gfmTableHtml: HtmlExtension
export function gfmTableHtml(): HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type Align = import('./infer.js').Align

@@ -9,3 +9,3 @@ /**

import {ok as assert} from 'uvu/assert'
import {ok as assert} from 'devlop'

@@ -19,121 +19,124 @@ const alignment = {

// To do: next major: expose functions.
// To do: next major: use `infer` here, when all events are exposed.
// To do: micromark@5: use `infer` here, when all events are exposed.
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to support
* GFM tables when serializing to HTML.
* Create an HTML extension for `micromark` to support GitHub tables when
* serializing to HTML.
*
* @type {HtmlExtension}
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GitHub tables when serializing to HTML.
*/
export const gfmTableHtml = {
enter: {
table(token) {
const tableAlign = token._align
assert(tableAlign, 'expected `_align`')
this.lineEndingIfNeeded()
this.tag('<table>')
this.setData('tableAlign', tableAlign)
},
tableBody() {
this.tag('<tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
const align = alignment[tableAlign[tableColumn]]
export function gfmTableHtml() {
return {
enter: {
table(token) {
const tableAlign = token._align
assert(tableAlign, 'expected `_align`')
this.lineEndingIfNeeded()
this.tag('<table>')
this.setData('tableAlign', tableAlign)
},
tableBody() {
this.tag('<tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
const align = alignment[tableAlign[tableColumn]]
if (align === undefined) {
// Capture results to ignore them.
this.buffer()
} else {
if (align === undefined) {
// Capture results to ignore them.
this.buffer()
} else {
this.lineEndingIfNeeded()
this.tag('<td' + align + '>')
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('<td' + align + '>')
this.tag('<thead>')
},
tableHeader() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag('<th' + align + '>')
},
tableRow() {
this.setData('tableColumn', 0)
this.lineEndingIfNeeded()
this.tag('<tr>')
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('<thead>')
},
tableHeader() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag('<th' + align + '>')
},
tableRow() {
this.setData('tableColumn', 0)
this.lineEndingIfNeeded()
this.tag('<tr>')
}
},
exit: {
// Overwrite the default code text data handler to unescape escaped pipes when
// they are in tables.
codeTextData(token) {
let value = this.sliceSerialize(token)
exit: {
// Overwrite the default code text data handler to unescape escaped pipes when
// they are in tables.
codeTextData(token) {
let value = this.sliceSerialize(token)
if (this.getData('tableAlign')) {
value = value.replace(/\\([\\|])/g, replace)
}
if (this.getData('tableAlign')) {
value = value.replace(/\\([\\|])/g, replace)
}
this.raw(this.encode(value))
},
table() {
this.setData('tableAlign')
// Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows,
// but we do need to reset it to match a funky newline GH generates for
// list items combined with tables.
this.setData('slurpAllLineEndings')
this.lineEndingIfNeeded()
this.tag('</table>')
},
tableBody() {
this.lineEndingIfNeeded()
this.tag('</tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
this.raw(this.encode(value))
},
table() {
this.setData('tableAlign')
// Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows,
// but we do need to reset it to match a funky newline GH generates for
// list items combined with tables.
this.setData('slurpAllLineEndings')
this.lineEndingIfNeeded()
this.tag('</table>')
},
tableBody() {
this.lineEndingIfNeeded()
this.tag('</tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
if (tableColumn in tableAlign) {
this.tag('</td>')
if (tableColumn in tableAlign) {
this.tag('</td>')
this.setData('tableColumn', tableColumn + 1)
} else {
// Stop capturing.
this.resume()
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('</thead>')
},
tableHeader() {
const tableColumn = this.getData('tableColumn')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
} else {
// Stop capturing.
this.resume()
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('</thead>')
},
tableHeader() {
const tableColumn = this.getData('tableColumn')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
},
tableRow() {
const tableAlign = this.getData('tableAlign')
let tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
},
tableRow() {
const tableAlign = this.getData('tableAlign')
let tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
while (tableColumn < tableAlign.length) {
while (tableColumn < tableAlign.length) {
this.lineEndingIfNeeded()
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
}
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
this.tag('</tr>')
}
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()
this.tag('</tr>')
}

@@ -140,0 +143,0 @@ }

/**
* Figure out the alignment of a GFM table.
*
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* List of events.
* @param {number} index
* Table enter event.
* @returns {Array<Align>}
* List of aligns.
*/
export function gfmTableAlign(
events: Array<import('micromark-util-types').Event>,
events: Readonly<Array<import('micromark-util-types').Event>>,
index: number
): Array<Align>
export type Event = import('micromark-util-types').Event
export type Align = 'left' | 'center' | 'right' | 'none'
export type Align = 'center' | 'left' | 'none' | 'right'

@@ -6,6 +6,6 @@ /**

/**
* @typedef {'left' | 'center' | 'right' | 'none'} Align
* @typedef {'center' | 'left' | 'none' | 'right'} Align
*/
import {ok as assert} from 'uvu/assert'
import {ok as assert} from 'devlop'

@@ -15,5 +15,8 @@ /**

*
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* List of events.
* @param {number} index
* Table enter event.
* @returns {Array<Align>}
* List of aligns.
*/

@@ -20,0 +23,0 @@ export function gfmTableAlign(events, index) {

/**
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
* Create an HTML extension for `micromark` to support GitHub tables syntax.
*
* @type {Extension}
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
*/
export const gfmTable: Extension
export function gfmTable(): Extension
export type Event = import('micromark-util-types').Event

@@ -9,0 +10,0 @@ export type Extension = import('micromark-util-types').Extension

@@ -20,3 +20,3 @@ /**

import {ok as assert} from 'uvu/assert'
import {ok as assert} from 'devlop'
import {factorySpace} from 'micromark-factory-space'

@@ -28,18 +28,17 @@ import {

} from 'micromark-util-character'
import {codes} from 'micromark-util-symbol/codes.js'
import {constants} from 'micromark-util-symbol/constants.js'
import {types} from 'micromark-util-symbol/types.js'
import {codes, constants, types} from 'micromark-util-symbol'
import {EditMap} from './edit-map.js'
import {gfmTableAlign} from './infer.js'
// To do: next major: expose functions.
/**
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
* Create an HTML extension for `micromark` to support GitHub tables syntax.
*
* @type {Extension}
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
*/
export const gfmTable = {
flow: {null: {tokenize: tokenizeTable, resolveAll: resolveTable}}
export function gfmTable() {
return {
flow: {null: {tokenize: tokenizeTable, resolveAll: resolveTable}}
}
}

@@ -632,3 +631,3 @@

/** @type {Resolver} */
// eslint-disable-next-line complexity
function resolveTable(events, context) {

@@ -805,8 +804,8 @@ let index = -1

/// Generate a cell.
/**
* Generate a cell.
*
* @param {EditMap} map
* @param {TokenizeContext} context
* @param {Range} range
* @param {Readonly<TokenizeContext>} context
* @param {Readonly<Range>} range
* @param {RowKind} rowKind

@@ -919,4 +918,4 @@ * @param {number | undefined} rowEnd

*
* @param {EditMap} map
* @param {TokenizeContext} context
* @param {Readonly<EditMap>} map
* @param {Readonly<TokenizeContext>} context
* @param {number} index

@@ -944,5 +943,5 @@ * @param {Token} table

/**
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* @param {number} index
* @returns {readonly Point}
* @returns {Readonly<Point>}
*/

@@ -949,0 +948,0 @@ function getPoint(events, index) {

@@ -7,3 +7,2 @@ import type {Align} from './lib/infer.js'

declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Token {

@@ -13,3 +12,2 @@ _align?: Align[]

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface TokenTypeMap {

@@ -30,3 +28,2 @@ table: 'table'

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CompileData {

@@ -33,0 +30,0 @@ tableAlign?: Align[]

@@ -24,3 +24,3 @@ /**

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -31,3 +31,3 @@ add(

add: Array<import('micromark-util-types').Event>
): void
): undefined
/**

@@ -37,5 +37,5 @@ * Done, change the events.

* @param {Array<Event>} events
* @returns {void}
* @returns {undefined}
*/
consume(events: Array<import('micromark-util-types').Event>): void
consume(events: Array<import('micromark-util-types').Event>): undefined
}

@@ -42,0 +42,0 @@ export type Event = import('micromark-util-types').Event

@@ -45,3 +45,3 @@ /**

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -52,3 +52,3 @@ add(index, remove, add) {

// To do: not used here.
// To do: add this when moving to `micromark`.
// /**

@@ -60,3 +60,3 @@ // * Create an edit: but insert `add` before existing additions.

// * @param {Array<Event>} add
// * @returns {void}
// * @returns {undefined}
// */

@@ -71,6 +71,8 @@ // addBefore(index, remove, add) {

* @param {Array<Event>} events
* @returns {void}
* @returns {undefined}
*/
consume(events) {
this.map.sort((a, b) => a[0] - b[0])
this.map.sort(function (a, b) {
return a[0] - b[0]
})

@@ -105,5 +107,6 @@ /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */

index -= 1
vecs.push(events.slice(this.map[index][0] + this.map[index][1]))
// eslint-disable-next-line unicorn/no-array-push-push
vecs.push(this.map[index][2])
vecs.push(
events.slice(this.map[index][0] + this.map[index][1]),
this.map[index][2]
)

@@ -133,3 +136,3 @@ // Truncate rest.

* @param {Array<Event>} add
* @returns {void}
* @returns {undefined}
*/

@@ -147,3 +150,3 @@ function addImpl(editMap, at, remove, add) {

// To do: before not used.
// To do: before not used by tables, use when moving to micromark.
// if (before) {

@@ -190,3 +193,2 @@ // add.push(...editMap.map[index][2])

// } else {
// console.log('to do: links?', add, rmCurr)
// // ?

@@ -193,0 +195,0 @@ // // if let Some(link) = &events[index].link {

/**
* Extension for `micromark` that can be passed in `htmlExtensions` to support
* GFM tables when serializing to HTML.
* Create an HTML extension for `micromark` to support GitHub tables when
* serializing to HTML.
*
* @type {HtmlExtension}
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GitHub tables when serializing to HTML.
*/
export const gfmTableHtml: HtmlExtension
export function gfmTableHtml(): HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type Align = import('./infer.js').Align

@@ -16,105 +16,108 @@ /**

// To do: next major: expose functions.
// To do: next major: use `infer` here, when all events are exposed.
// To do: micromark@5: use `infer` here, when all events are exposed.
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to support
* GFM tables when serializing to HTML.
* Create an HTML extension for `micromark` to support GitHub tables when
* serializing to HTML.
*
* @type {HtmlExtension}
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GitHub tables when serializing to HTML.
*/
export const gfmTableHtml = {
enter: {
table(token) {
const tableAlign = token._align
this.lineEndingIfNeeded()
this.tag('<table>')
this.setData('tableAlign', tableAlign)
},
tableBody() {
this.tag('<tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
if (align === undefined) {
// Capture results to ignore them.
this.buffer()
} else {
export function gfmTableHtml() {
return {
enter: {
table(token) {
const tableAlign = token._align
this.lineEndingIfNeeded()
this.tag('<td' + align + '>')
this.tag('<table>')
this.setData('tableAlign', tableAlign)
},
tableBody() {
this.tag('<tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
if (align === undefined) {
// Capture results to ignore them.
this.buffer()
} else {
this.lineEndingIfNeeded()
this.tag('<td' + align + '>')
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('<thead>')
},
tableHeader() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag('<th' + align + '>')
},
tableRow() {
this.setData('tableColumn', 0)
this.lineEndingIfNeeded()
this.tag('<tr>')
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('<thead>')
},
tableHeader() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag('<th' + align + '>')
},
tableRow() {
this.setData('tableColumn', 0)
this.lineEndingIfNeeded()
this.tag('<tr>')
}
},
exit: {
// Overwrite the default code text data handler to unescape escaped pipes when
// they are in tables.
codeTextData(token) {
let value = this.sliceSerialize(token)
if (this.getData('tableAlign')) {
value = value.replace(/\\([\\|])/g, replace)
}
this.raw(this.encode(value))
},
table() {
this.setData('tableAlign')
// Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows,
// but we do need to reset it to match a funky newline GH generates for
// list items combined with tables.
this.setData('slurpAllLineEndings')
this.lineEndingIfNeeded()
this.tag('</table>')
},
tableBody() {
this.lineEndingIfNeeded()
this.tag('</tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
if (tableColumn in tableAlign) {
this.tag('</td>')
exit: {
// Overwrite the default code text data handler to unescape escaped pipes when
// they are in tables.
codeTextData(token) {
let value = this.sliceSerialize(token)
if (this.getData('tableAlign')) {
value = value.replace(/\\([\\|])/g, replace)
}
this.raw(this.encode(value))
},
table() {
this.setData('tableAlign')
// Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows,
// but we do need to reset it to match a funky newline GH generates for
// list items combined with tables.
this.setData('slurpAllLineEndings')
this.lineEndingIfNeeded()
this.tag('</table>')
},
tableBody() {
this.lineEndingIfNeeded()
this.tag('</tbody>')
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
if (tableColumn in tableAlign) {
this.tag('</td>')
this.setData('tableColumn', tableColumn + 1)
} else {
// Stop capturing.
this.resume()
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('</thead>')
},
tableHeader() {
const tableColumn = this.getData('tableColumn')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
} else {
// Stop capturing.
this.resume()
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('</thead>')
},
tableHeader() {
const tableColumn = this.getData('tableColumn')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
},
tableRow() {
const tableAlign = this.getData('tableAlign')
let tableColumn = this.getData('tableColumn')
while (tableColumn < tableAlign.length) {
},
tableRow() {
const tableAlign = this.getData('tableAlign')
let tableColumn = this.getData('tableColumn')
while (tableColumn < tableAlign.length) {
this.lineEndingIfNeeded()
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
}
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>')
tableColumn++
this.tag('</tr>')
}
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()
this.tag('</tr>')
}

@@ -121,0 +124,0 @@ }

/**
* Figure out the alignment of a GFM table.
*
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* List of events.
* @param {number} index
* Table enter event.
* @returns {Array<Align>}
* List of aligns.
*/
export function gfmTableAlign(
events: Array<import('micromark-util-types').Event>,
events: Readonly<Array<import('micromark-util-types').Event>>,
index: number
): Array<Align>
export type Event = import('micromark-util-types').Event
export type Align = 'left' | 'center' | 'right' | 'none'
export type Align = 'center' | 'left' | 'none' | 'right'

@@ -6,3 +6,3 @@ /**

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

@@ -13,5 +13,8 @@

*
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* List of events.
* @param {number} index
* Table enter event.
* @returns {Array<Align>}
* List of aligns.
*/

@@ -18,0 +21,0 @@ export function gfmTableAlign(events, index) {

/**
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
* Create an HTML extension for `micromark` to support GitHub tables syntax.
*
* @type {Extension}
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
*/
export const gfmTable: Extension
export function gfmTable(): Extension
export type Event = import('micromark-util-types').Event

@@ -9,0 +10,0 @@ export type Extension = import('micromark-util-types').Extension

@@ -29,15 +29,16 @@ /**

// To do: next major: expose functions.
/**
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
* Create an HTML extension for `micromark` to support GitHub tables syntax.
*
* @type {Extension}
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* table syntax.
*/
export const gfmTable = {
flow: {
null: {
tokenize: tokenizeTable,
resolveAll: resolveTable
export function gfmTable() {
return {
flow: {
null: {
tokenize: tokenizeTable,
resolveAll: resolveTable
}
}

@@ -587,3 +588,3 @@ }

/** @type {Resolver} */
// eslint-disable-next-line complexity
function resolveTable(events, context) {

@@ -747,8 +748,8 @@ let index = -1

/// Generate a cell.
/**
* Generate a cell.
*
* @param {EditMap} map
* @param {TokenizeContext} context
* @param {Range} range
* @param {Readonly<TokenizeContext>} context
* @param {Readonly<Range>} range
* @param {RowKind} rowKind

@@ -856,4 +857,4 @@ * @param {number | undefined} rowEnd

*
* @param {EditMap} map
* @param {TokenizeContext} context
* @param {Readonly<EditMap>} map
* @param {Readonly<TokenizeContext>} context
* @param {number} index

@@ -878,5 +879,5 @@ * @param {Token} table

/**
* @param {Array<Event>} events
* @param {Readonly<Array<Event>>} events
* @param {number} index
* @returns {readonly Point}
* @returns {Readonly<Point>}
*/

@@ -883,0 +884,0 @@ function getPoint(events, index) {

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

@@ -30,4 +30,2 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [

@@ -44,14 +42,14 @@ "dev/",

"dependencies": {
"micromark-factory-space": "^1.0.0",
"micromark-util-character": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
"uvu": "^0.5.0"
"devlop": "^1.0.0",
"micromark-factory-space": "^2.0.0",
"micromark-util-character": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"c8": "^7.0.0",
"c8": "^8.0.0",
"create-gfm-fixtures": "^1.0.0",
"micromark": "^3.0.0",
"micromark-build": "^1.0.0",
"micromark": "^4.0.0",
"micromark-build": "^2.0.0",
"prettier": "^2.0.0",

@@ -75,16 +73,21 @@ "remark-cli": "^11.0.0",

"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"max-depth": "off",
"n/file-extension-in-import": "off",
"unicorn/no-this-assignment": "off"
},
"overrides": [

@@ -98,16 +101,19 @@ {

}
},
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": 0
}
}
]
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
],
"prettier": true,
"rules": {
"complexity": "off",
"max-depth": "off",
"unicorn/no-this-assignment": "off"
}
}
}

@@ -20,4 +20,4 @@ # micromark-extension-gfm-table

* [API](#api)
* [`gfmTable`](#gfmtable)
* [`gfmTableHtml`](#gfmtablehtml)
* [`gfmTable()`](#gfmtable)
* [`gfmTableHtml()`](#gfmtablehtml)
* [Bugs](#bugs)

@@ -67,3 +67,3 @@ * [Authoring](#authoring)

```js
import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@1'
import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2'
```

@@ -75,3 +75,3 @@

<script type="module">
import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@1?bundle'
import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2?bundle'
</script>

@@ -87,4 +87,4 @@ ```

const output = micromark('| a |\n| - |', {
extensions: [gfmTable],
htmlExtensions: [gfmTableHtml]
extensions: [gfmTable()],
htmlExtensions: [gfmTableHtml()]
})

@@ -117,9 +117,18 @@

### `gfmTable`
### `gfmTable()`
Create an HTML extension for `micromark` to support GitHub tables syntax.
###### Returns
Extension for `micromark` that can be passed in `extensions` to enable GFM
table syntax ([`Extension`][micromark-extension]).
### `gfmTableHtml`
### `gfmTableHtml()`
Create an HTML extension for `micromark` to support GitHub tables when
serializing to HTML.
###### Returns
Extension for `micromark` that can be passed in `htmlExtensions` to support

@@ -390,9 +399,12 @@ GFM tables when serializing to HTML

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 16+.
Our projects sometimes work with older versions, but this is not guaranteed.
These extensions work with `micromark` version 3+.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-extension-gfm-table@^2`, compatible with Node.js 16.
This package works with `micromark` version `3` and later.
## Security

@@ -441,5 +453,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-extension-gfm-table.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-table
[size]: https://bundlephobia.com/result?p=micromark-extension-gfm-table
[size]: https://bundlejs.com/?q=micromark-extension-gfm-table

@@ -446,0 +458,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

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