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
0
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 2.0.0 to 2.1.0

7

dev/index.d.ts

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

/**
* Augment types.
*/
declare module 'micromark-util-types' {
/**
* Augment token;
* `align` is patched on `table` tokens.
*/
interface Token {

@@ -9,0 +16,0 @@ _align?: Align[]

66

dev/lib/edit-map.d.ts
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -12,41 +12,27 @@ /**

export class EditMap {
/**
* Record of changes.
*
* @type {Array<Change>}
*/
map: Array<Change>
/**
* Create an edit: a remove and/or add at a certain place.
*
* @param {number} index
* @param {number} remove
* @param {Array<Event>} add
* @returns {undefined}
*/
add(
index: number,
remove: number,
add: Array<import('micromark-util-types').Event>
): undefined
/**
* Done, change the events.
*
* @param {Array<Event>} events
* @returns {undefined}
*/
consume(events: Array<import('micromark-util-types').Event>): undefined
/**
* Record of changes.
*
* @type {Array<Change>}
*/
map: Array<Change>;
/**
* Create an edit: a remove and/or add at a certain place.
*
* @param {number} index
* @param {number} remove
* @param {Array<Event>} add
* @returns {undefined}
*/
add(index: number, remove: number, add: Array<Event>): undefined;
/**
* Done, change the events.
*
* @param {Array<Event>} events
* @returns {undefined}
*/
consume(events: Array<Event>): undefined;
}
export type Event = import('micromark-util-types').Event
export type Change = [
number,
number,
Array<
[
'enter' | 'exit',
import('micromark-util-types').Token,
import('micromark-util-types').TokenizeContext
]
>
]
export type Jump = [number, number, number]
export type Change = [number, number, Array<Event>];
export type Jump = [number, number, number];
import type { Event } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -48,3 +48,3 @@

add(index, remove, add) {
addImpl(this, index, remove, add)
addImplementation(this, index, remove, add)
}

@@ -62,3 +62,3 @@

// addBefore(index, remove, add) {
// addImpl(this, index, remove, add, true)
// addImplementation(this, index, remove, add, true)
// }

@@ -138,3 +138,3 @@

*/
function addImpl(editMap, at, remove, add) {
function addImplementation(editMap, at, remove, add) {
let index = 0

@@ -141,0 +141,0 @@

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

*/
export function gfmTableHtml(): HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type Align = import('./infer.js').Align
export function gfmTableHtml(): HtmlExtension;
import type { HtmlExtension } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
* @import {HtmlExtension} from 'micromark-util-types'
*/
/**
* @typedef {import('./infer.js').Align} Align
*/
import {ok as assert} from 'devlop'

@@ -10,0 +6,0 @@

@@ -11,7 +11,4 @@ /**

*/
export function gfmTableAlign(
events: Readonly<Array<import('micromark-util-types').Event>>,
index: number
): Array<Align>
export type Event = import('micromark-util-types').Event
export type Align = 'center' | 'left' | 'none' | 'right'
export function gfmTableAlign(events: Readonly<Array<Event>>, index: number): Array<Align>;
export type Align = "center" | "left" | "none" | "right";
import type { Event } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -4,0 +4,0 @@

@@ -8,18 +8,11 @@ /**

*/
export function gfmTable(): Extension
export type Event = import('micromark-util-types').Event
export type Extension = import('micromark-util-types').Extension
export type Point = import('micromark-util-types').Point
export type Resolver = import('micromark-util-types').Resolver
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export function gfmTable(): Extension;
/**
* Cell info.
*/
export type Range = [number, number, number, number]
export type Range = [number, number, number, number];
/**
* Where we are: `1` for head row, `2` for delimiter row, `3` for body row.
*/
export type RowKind = 0 | 1 | 2 | 3
export type RowKind = 0 | 1 | 2 | 3;
import type { Extension } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @import {Event, Extension, Point, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/

@@ -40,3 +33,5 @@

return {
flow: {null: {tokenize: tokenizeTable, resolveAll: resolveTable}}
flow: {
null: {name: 'table', tokenize: tokenizeTable, resolveAll: resolveTable}
}
}

@@ -821,4 +816,4 @@ }

: rowKind === 2
? 'tableDelimiter'
: 'tableData'
? 'tableDelimiter'
: 'tableData'
// `markdown-rs` uses:

@@ -825,0 +820,0 @@ // rowKind === 2 ? 'tableDelimiterCellValue' : 'tableCellText'

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

/**
* Augment types.
*/
declare module 'micromark-util-types' {
/**
* Augment token;
* `align` is patched on `table` tokens.
*/
interface Token {

@@ -9,0 +16,0 @@ _align?: Align[]

@@ -1,2 +0,2 @@

export {gfmTableHtml} from './lib/html.js'
export {gfmTable} from './lib/syntax.js'
export { gfmTableHtml } from './lib/html.js';
export { gfmTable } from './lib/syntax.js';
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -12,41 +12,27 @@ /**

export class EditMap {
/**
* Record of changes.
*
* @type {Array<Change>}
*/
map: Array<Change>
/**
* Create an edit: a remove and/or add at a certain place.
*
* @param {number} index
* @param {number} remove
* @param {Array<Event>} add
* @returns {undefined}
*/
add(
index: number,
remove: number,
add: Array<import('micromark-util-types').Event>
): undefined
/**
* Done, change the events.
*
* @param {Array<Event>} events
* @returns {undefined}
*/
consume(events: Array<import('micromark-util-types').Event>): undefined
/**
* Record of changes.
*
* @type {Array<Change>}
*/
map: Array<Change>;
/**
* Create an edit: a remove and/or add at a certain place.
*
* @param {number} index
* @param {number} remove
* @param {Array<Event>} add
* @returns {undefined}
*/
add(index: number, remove: number, add: Array<Event>): undefined;
/**
* Done, change the events.
*
* @param {Array<Event>} events
* @returns {undefined}
*/
consume(events: Array<Event>): undefined;
}
export type Event = import('micromark-util-types').Event
export type Change = [
number,
number,
Array<
[
'enter' | 'exit',
import('micromark-util-types').Token,
import('micromark-util-types').TokenizeContext
]
>
]
export type Jump = [number, number, number]
export type Change = [number, number, Array<Event>];
export type Jump = [number, number, number];
import type { Event } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -36,3 +36,3 @@

*/
this.map = []
this.map = [];
}

@@ -49,3 +49,3 @@

add(index, remove, add) {
addImpl(this, index, remove, add)
addImplementation(this, index, remove, add);
}

@@ -63,3 +63,3 @@

// addBefore(index, remove, add) {
// addImpl(this, index, remove, add, true)
// addImplementation(this, index, remove, add, true)
// }

@@ -75,8 +75,8 @@

this.map.sort(function (a, b) {
return a[0] - b[0]
})
return a[0] - b[0];
});
/* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */
if (this.map.length === 0) {
return
return;
}

@@ -102,25 +102,22 @@

let index = this.map.length
let index = this.map.length;
/** @type {Array<Array<Event>>} */
const vecs = []
const vecs = [];
while (index > 0) {
index -= 1
vecs.push(
events.slice(this.map[index][0] + this.map[index][1]),
this.map[index][2]
)
index -= 1;
vecs.push(events.slice(this.map[index][0] + this.map[index][1]), this.map[index][2]);
// Truncate rest.
events.length = this.map[index][0]
events.length = this.map[index][0];
}
vecs.push([...events])
events.length = 0
let slice = vecs.pop()
vecs.push([...events]);
events.length = 0;
let slice = vecs.pop();
while (slice) {
events.push(...slice)
slice = vecs.pop()
events.push(...slice);
slice = vecs.pop();
}
// Truncate everything.
this.map.length = 0
this.map.length = 0;
}

@@ -138,12 +135,12 @@ }

*/
function addImpl(editMap, at, remove, add) {
let index = 0
function addImplementation(editMap, at, remove, add) {
let index = 0;
/* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */
if (remove === 0 && add.length === 0) {
return
return;
}
while (index < editMap.map.length) {
if (editMap.map[index][0] === at) {
editMap.map[index][1] += remove
editMap.map[index][1] += remove;

@@ -155,10 +152,10 @@ // To do: before not used by tables, use when moving to micromark.

// } else {
editMap.map[index][2].push(...add)
editMap.map[index][2].push(...add);
// }
return
return;
}
index += 1
index += 1;
}
editMap.map.push([at, remove, add])
editMap.map.push([at, remove, add]);
}

@@ -210,2 +207,2 @@

// }
// }
// }

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

*/
export function gfmTableHtml(): HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type Align = import('./infer.js').Align
export function gfmTableHtml(): HtmlExtension;
import type { HtmlExtension } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
* @import {HtmlExtension} from 'micromark-util-types'
*/
/**
* @typedef {import('./infer.js').Align} Align
*/
const alignment = {

@@ -14,3 +10,3 @@ none: '',

center: ' align="center"'
}
};

@@ -31,37 +27,37 @@ // To do: micromark@5: use `infer` here, when all events are exposed.

table(token) {
const tableAlign = token._align
this.lineEndingIfNeeded()
this.tag('<table>')
this.setData('tableAlign', tableAlign)
const tableAlign = token._align;
this.lineEndingIfNeeded();
this.tag('<table>');
this.setData('tableAlign', tableAlign);
},
tableBody() {
this.tag('<tbody>')
this.tag('<tbody>');
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const align = alignment[tableAlign[tableColumn]]
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()
this.buffer();
} else {
this.lineEndingIfNeeded()
this.tag('<td' + align + '>')
this.lineEndingIfNeeded();
this.tag('<td' + align + '>');
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('<thead>')
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 + '>')
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>')
this.setData('tableColumn', 0);
this.lineEndingIfNeeded();
this.tag('<tr>');
}

@@ -73,55 +69,55 @@ },

codeTextData(token) {
let value = this.sliceSerialize(token)
let value = this.sliceSerialize(token);
if (this.getData('tableAlign')) {
value = value.replace(/\\([\\|])/g, replace)
value = value.replace(/\\([\\|])/g, replace);
}
this.raw(this.encode(value))
this.raw(this.encode(value));
},
table() {
this.setData('tableAlign')
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>')
this.setData('slurpAllLineEndings');
this.lineEndingIfNeeded();
this.tag('</table>');
},
tableBody() {
this.lineEndingIfNeeded()
this.tag('</tbody>')
this.lineEndingIfNeeded();
this.tag('</tbody>');
},
tableData() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
const tableAlign = this.getData('tableAlign');
const tableColumn = this.getData('tableColumn');
if (tableColumn in tableAlign) {
this.tag('</td>')
this.setData('tableColumn', tableColumn + 1)
this.tag('</td>');
this.setData('tableColumn', tableColumn + 1);
} else {
// Stop capturing.
this.resume()
this.resume();
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('</thead>')
this.lineEndingIfNeeded();
this.tag('</thead>');
},
tableHeader() {
const tableColumn = this.getData('tableColumn')
this.tag('</th>')
this.setData('tableColumn', tableColumn + 1)
const tableColumn = this.getData('tableColumn');
this.tag('</th>');
this.setData('tableColumn', tableColumn + 1);
},
tableRow() {
const tableAlign = this.getData('tableAlign')
let tableColumn = this.getData('tableColumn')
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.lineEndingIfNeeded();
this.tag('<td' + alignment[tableAlign[tableColumn]] + '></td>');
tableColumn++;
}
this.setData('tableColumn', tableColumn)
this.lineEndingIfNeeded()
this.tag('</tr>')
this.setData('tableColumn', tableColumn);
this.lineEndingIfNeeded();
this.tag('</tr>');
}
}
}
};
}

@@ -136,3 +132,3 @@

// Pipes work, backslashes don’t (but can’t escape pipes).
return $1 === '|' ? $1 : $0
}
return $1 === '|' ? $1 : $0;
}

@@ -11,7 +11,4 @@ /**

*/
export function gfmTableAlign(
events: Readonly<Array<import('micromark-util-types').Event>>,
index: number
): Array<Align>
export type Event = import('micromark-util-types').Event
export type Align = 'center' | 'left' | 'none' | 'right'
export function gfmTableAlign(events: Readonly<Array<Event>>, index: number): Array<Align>;
export type Align = "center" | "left" | "none" | "right";
import type { Event } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @import {Event} from 'micromark-util-types'
*/

@@ -20,7 +20,7 @@

export function gfmTableAlign(events, index) {
let inDelimiterRow = false
let inDelimiterRow = false;
/** @type {Array<Align>} */
const align = []
const align = [];
while (index < events.length) {
const event = events[index]
const event = events[index];
if (inDelimiterRow) {

@@ -31,7 +31,3 @@ if (event[0] === 'enter') {

if (event[1].type === 'tableContent') {
align.push(
events[index + 1][1].type === 'tableDelimiterMarker'
? 'left'
: 'none'
)
align.push(events[index + 1][1].type === 'tableDelimiterMarker' ? 'left' : 'none');
}

@@ -44,4 +40,4 @@ }

if (events[index - 1][1].type === 'tableDelimiterMarker') {
const alignIndex = align.length - 1
align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right'
const alignIndex = align.length - 1;
align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right';
}

@@ -51,10 +47,10 @@ }

else if (event[1].type === 'tableDelimiterRow') {
break
break;
}
} else if (event[0] === 'enter' && event[1].type === 'tableDelimiterRow') {
inDelimiterRow = true
inDelimiterRow = true;
}
index += 1
index += 1;
}
return align
}
return align;
}

@@ -8,18 +8,11 @@ /**

*/
export function gfmTable(): Extension
export type Event = import('micromark-util-types').Event
export type Extension = import('micromark-util-types').Extension
export type Point = import('micromark-util-types').Point
export type Resolver = import('micromark-util-types').Resolver
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export function gfmTable(): Extension;
/**
* Cell info.
*/
export type Range = [number, number, number, number]
export type Range = [number, number, number, number];
/**
* Where we are: `1` for head row, `2` for delimiter row, `3` for body row.
*/
export type RowKind = 0 | 1 | 2 | 3
export type RowKind = 0 | 1 | 2 | 3;
import type { Extension } from 'micromark-util-types';
/**
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @import {Event, Extension, Point, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/

@@ -20,10 +13,6 @@

import {factorySpace} from 'micromark-factory-space'
import {
markdownLineEnding,
markdownLineEndingOrSpace,
markdownSpace
} from 'micromark-util-character'
import {EditMap} from './edit-map.js'
import {gfmTableAlign} from './infer.js'
import { factorySpace } from 'micromark-factory-space';
import { markdownLineEnding, markdownLineEndingOrSpace, markdownSpace } from 'micromark-util-character';
import { EditMap } from './edit-map.js';
import { gfmTableAlign } from './infer.js';

@@ -41,2 +30,3 @@ /**

null: {
name: 'table',
tokenize: tokenizeTable,

@@ -46,3 +36,3 @@ resolveAll: resolveTable

}
}
};
}

@@ -55,8 +45,8 @@

function tokenizeTable(effects, ok, nok) {
const self = this
let size = 0
let sizeB = 0
const self = this;
let size = 0;
let sizeB = 0;
/** @type {boolean | undefined} */
let seen
return start
let seen;
return start;

@@ -80,22 +70,17 @@ /**

function start(code) {
let index = self.events.length - 1
let index = self.events.length - 1;
while (index > -1) {
const type = self.events[index][1].type
if (
type === 'lineEnding' ||
// Note: markdown-rs uses `whitespace` instead of `linePrefix`
type === 'linePrefix'
)
index--
else break
const type = self.events[index][1].type;
if (type === "lineEnding" ||
// Note: markdown-rs uses `whitespace` instead of `linePrefix`
type === "linePrefix") index--;else break;
}
const tail = index > -1 ? self.events[index][1].type : null
const next =
tail === 'tableHead' || tail === 'tableRow' ? bodyRowStart : headRowBefore
const tail = index > -1 ? self.events[index][1].type : null;
const next = tail === 'tableHead' || tail === 'tableRow' ? bodyRowStart : headRowBefore;
// Don’t allow lazy body rows.
if (next === bodyRowStart && self.parser.lazy[self.now().line]) {
return nok(code)
return nok(code);
}
return next(code)
return next(code);
}

@@ -116,5 +101,5 @@

function headRowBefore(code) {
effects.enter('tableHead')
effects.enter('tableRow')
return headRowStart(code)
effects.enter('tableHead');
effects.enter('tableRow');
return headRowStart(code);
}

@@ -136,3 +121,3 @@

if (code === 124) {
return headRowBreak(code)
return headRowBreak(code);
}

@@ -150,6 +135,6 @@

seen = true
seen = true;
// Count the first character, that isn’t a pipe, double.
sizeB += 1
return headRowBreak(code)
sizeB += 1;
return headRowBreak(code);
}

@@ -174,3 +159,3 @@

// Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
return nok(code)
return nok(code);
}

@@ -180,15 +165,15 @@ if (markdownLineEnding(code)) {

if (sizeB > 1) {
sizeB = 0
sizeB = 0;
// To do: check if this works.
// Feel free to interrupt:
self.interrupt = true
effects.exit('tableRow')
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return headDelimiterStart
self.interrupt = true;
effects.exit('tableRow');
effects.enter("lineEnding");
effects.consume(code);
effects.exit("lineEnding");
return headDelimiterStart;
}
// Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
return nok(code)
return nok(code);
}

@@ -199,22 +184,22 @@ if (markdownSpace(code)) {

// State::Retry(space_or_tab(tokenizer))
return factorySpace(effects, headRowBreak, 'whitespace')(code)
return factorySpace(effects, headRowBreak, "whitespace")(code);
}
sizeB += 1
sizeB += 1;
if (seen) {
seen = false
seen = false;
// Header cell count.
size += 1
size += 1;
}
if (code === 124) {
effects.enter('tableCellDivider')
effects.consume(code)
effects.exit('tableCellDivider')
effects.enter('tableCellDivider');
effects.consume(code);
effects.exit('tableCellDivider');
// Whether a delimiter was seen.
seen = true
return headRowBreak
seen = true;
return headRowBreak;
}
// Anything else is cell data.
effects.enter('data')
return headRowData(code)
effects.enter("data");
return headRowData(code);
}

@@ -236,7 +221,7 @@

if (code === null || code === 124 || markdownLineEndingOrSpace(code)) {
effects.exit('data')
return headRowBreak(code)
effects.exit("data");
return headRowBreak(code);
}
effects.consume(code)
return code === 92 ? headRowEscape : headRowData
effects.consume(code);
return code === 92 ? headRowEscape : headRowData;
}

@@ -258,6 +243,6 @@

if (code === 92 || code === 124) {
effects.consume(code)
return headRowData
effects.consume(code);
return headRowData;
}
return headRowData(code)
return headRowData(code);
}

@@ -279,22 +264,15 @@

// Reset `interrupt`.
self.interrupt = false
self.interrupt = false;
// Note: in `markdown-rs`, we need to handle piercing here too.
if (self.parser.lazy[self.now().line]) {
return nok(code)
return nok(code);
}
effects.enter('tableDelimiterRow')
effects.enter('tableDelimiterRow');
// Track if we’ve seen a `:` or `|`.
seen = false
seen = false;
if (markdownSpace(code)) {
return factorySpace(
effects,
headDelimiterBefore,
'linePrefix',
self.parser.constructs.disable.null.includes('codeIndented')
? undefined
: 4
)(code)
return factorySpace(effects, headDelimiterBefore, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code);
}
return headDelimiterBefore(code)
return headDelimiterBefore(code);
}

@@ -318,15 +296,15 @@

if (code === 45 || code === 58) {
return headDelimiterValueBefore(code)
return headDelimiterValueBefore(code);
}
if (code === 124) {
seen = true
seen = true;
// If we start with a pipe, we open a cell marker.
effects.enter('tableCellDivider')
effects.consume(code)
effects.exit('tableCellDivider')
return headDelimiterCellBefore
effects.enter('tableCellDivider');
effects.consume(code);
effects.exit('tableCellDivider');
return headDelimiterCellBefore;
}
// More whitespace / empty row not allowed at start.
return headDelimiterNok(code)
return headDelimiterNok(code);
}

@@ -347,5 +325,5 @@

if (markdownSpace(code)) {
return factorySpace(effects, headDelimiterValueBefore, 'whitespace')(code)
return factorySpace(effects, headDelimiterValueBefore, "whitespace")(code);
}
return headDelimiterValueBefore(code)
return headDelimiterValueBefore(code);
}

@@ -367,8 +345,8 @@

if (code === 58) {
sizeB += 1
seen = true
effects.enter('tableDelimiterMarker')
effects.consume(code)
effects.exit('tableDelimiterMarker')
return headDelimiterLeftAlignmentAfter
sizeB += 1;
seen = true;
effects.enter('tableDelimiterMarker');
effects.consume(code);
effects.exit('tableDelimiterMarker');
return headDelimiterLeftAlignmentAfter;
}

@@ -378,10 +356,10 @@

if (code === 45) {
sizeB += 1
sizeB += 1;
// To do: seems weird that this *isn’t* left aligned, but that state is used?
return headDelimiterLeftAlignmentAfter(code)
return headDelimiterLeftAlignmentAfter(code);
}
if (code === null || markdownLineEnding(code)) {
return headDelimiterCellAfter(code)
return headDelimiterCellAfter(code);
}
return headDelimiterNok(code)
return headDelimiterNok(code);
}

@@ -402,8 +380,8 @@

if (code === 45) {
effects.enter('tableDelimiterFiller')
return headDelimiterFiller(code)
effects.enter('tableDelimiterFiller');
return headDelimiterFiller(code);
}
// Anything else is not ok after the left-align colon.
return headDelimiterNok(code)
return headDelimiterNok(code);
}

@@ -424,4 +402,4 @@

if (code === 45) {
effects.consume(code)
return headDelimiterFiller
effects.consume(code);
return headDelimiterFiller;
}

@@ -431,11 +409,11 @@

if (code === 58) {
seen = true
effects.exit('tableDelimiterFiller')
effects.enter('tableDelimiterMarker')
effects.consume(code)
effects.exit('tableDelimiterMarker')
return headDelimiterRightAlignmentAfter
seen = true;
effects.exit('tableDelimiterFiller');
effects.enter('tableDelimiterMarker');
effects.consume(code);
effects.exit('tableDelimiterMarker');
return headDelimiterRightAlignmentAfter;
}
effects.exit('tableDelimiterFiller')
return headDelimiterRightAlignmentAfter(code)
effects.exit('tableDelimiterFiller');
return headDelimiterRightAlignmentAfter(code);
}

@@ -456,5 +434,5 @@

if (markdownSpace(code)) {
return factorySpace(effects, headDelimiterCellAfter, 'whitespace')(code)
return factorySpace(effects, headDelimiterCellAfter, "whitespace")(code);
}
return headDelimiterCellAfter(code)
return headDelimiterCellAfter(code);
}

@@ -475,3 +453,3 @@

if (code === 124) {
return headDelimiterBefore(code)
return headDelimiterBefore(code);
}

@@ -484,13 +462,13 @@ if (code === null || markdownLineEnding(code)) {

if (!seen || size !== sizeB) {
return headDelimiterNok(code)
return headDelimiterNok(code);
}
// Note: in markdown-rs`, a reset is needed here.
effects.exit('tableDelimiterRow')
effects.exit('tableHead')
effects.exit('tableDelimiterRow');
effects.exit('tableHead');
// To do: in `markdown-rs`, resolvers need to be registered manually.
// effects.register_resolver(ResolveName::GfmTable)
return ok(code)
return ok(code);
}
return headDelimiterNok(code)
return headDelimiterNok(code);
}

@@ -511,3 +489,3 @@

// Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
return nok(code)
return nok(code);
}

@@ -531,4 +509,4 @@

// never at whitespace.
effects.enter('tableRow')
return bodyRowBreak(code)
effects.enter('tableRow');
return bodyRowBreak(code);
}

@@ -552,18 +530,18 @@

if (code === 124) {
effects.enter('tableCellDivider')
effects.consume(code)
effects.exit('tableCellDivider')
return bodyRowBreak
effects.enter('tableCellDivider');
effects.consume(code);
effects.exit('tableCellDivider');
return bodyRowBreak;
}
if (code === null || markdownLineEnding(code)) {
effects.exit('tableRow')
return ok(code)
effects.exit('tableRow');
return ok(code);
}
if (markdownSpace(code)) {
return factorySpace(effects, bodyRowBreak, 'whitespace')(code)
return factorySpace(effects, bodyRowBreak, "whitespace")(code);
}
// Anything else is cell content.
effects.enter('data')
return bodyRowData(code)
effects.enter("data");
return bodyRowData(code);
}

@@ -585,7 +563,7 @@

if (code === null || code === 124 || markdownLineEndingOrSpace(code)) {
effects.exit('data')
return bodyRowBreak(code)
effects.exit("data");
return bodyRowBreak(code);
}
effects.consume(code)
return code === 92 ? bodyRowEscape : bodyRowData
effects.consume(code);
return code === 92 ? bodyRowEscape : bodyRowData;
}

@@ -607,6 +585,6 @@

if (code === 92 || code === 124) {
effects.consume(code)
return bodyRowData
effects.consume(code);
return bodyRowData;
}
return bodyRowData(code)
return bodyRowData(code);
}

@@ -618,32 +596,32 @@ }

function resolveTable(events, context) {
let index = -1
let inFirstCellAwaitingPipe = true
let index = -1;
let inFirstCellAwaitingPipe = true;
/** @type {RowKind} */
let rowKind = 0
let rowKind = 0;
/** @type {Range} */
let lastCell = [0, 0, 0, 0]
let lastCell = [0, 0, 0, 0];
/** @type {Range} */
let cell = [0, 0, 0, 0]
let afterHeadAwaitingFirstBodyRow = false
let lastTableEnd = 0
let cell = [0, 0, 0, 0];
let afterHeadAwaitingFirstBodyRow = false;
let lastTableEnd = 0;
/** @type {Token | undefined} */
let currentTable
let currentTable;
/** @type {Token | undefined} */
let currentBody
let currentBody;
/** @type {Token | undefined} */
let currentCell
const map = new EditMap()
let currentCell;
const map = new EditMap();
while (++index < events.length) {
const event = events[index]
const token = event[1]
const event = events[index];
const token = event[1];
if (event[0] === 'enter') {
// Start of head.
if (token.type === 'tableHead') {
afterHeadAwaitingFirstBodyRow = false
afterHeadAwaitingFirstBodyRow = false;
// Inject previous (body end and) table end.
if (lastTableEnd !== 0) {
flushTableEnd(map, context, lastTableEnd, currentTable, currentBody)
currentBody = undefined
lastTableEnd = 0
flushTableEnd(map, context, lastTableEnd, currentTable, currentBody);
currentBody = undefined;
lastTableEnd = 0;
}

@@ -657,16 +635,13 @@

end: Object.assign({}, token.end)
}
map.add(index, 0, [['enter', currentTable, context]])
} else if (
token.type === 'tableRow' ||
token.type === 'tableDelimiterRow'
) {
inFirstCellAwaitingPipe = true
currentCell = undefined
lastCell = [0, 0, 0, 0]
cell = [0, index + 1, 0, 0]
};
map.add(index, 0, [['enter', currentTable, context]]);
} else if (token.type === 'tableRow' || token.type === 'tableDelimiterRow') {
inFirstCellAwaitingPipe = true;
currentCell = undefined;
lastCell = [0, 0, 0, 0];
cell = [0, index + 1, 0, 0];
// Inject table body start.
if (afterHeadAwaitingFirstBodyRow) {
afterHeadAwaitingFirstBodyRow = false
afterHeadAwaitingFirstBodyRow = false;
currentBody = {

@@ -677,15 +652,10 @@ type: 'tableBody',

end: Object.assign({}, token.end)
}
map.add(index, 0, [['enter', currentBody, context]])
};
map.add(index, 0, [['enter', currentBody, context]]);
}
rowKind = token.type === 'tableDelimiterRow' ? 2 : currentBody ? 3 : 1
rowKind = token.type === 'tableDelimiterRow' ? 2 : currentBody ? 3 : 1;
}
// Cell data.
else if (
rowKind &&
(token.type === 'data' ||
token.type === 'tableDelimiterMarker' ||
token.type === 'tableDelimiterFiller')
) {
inFirstCellAwaitingPipe = false
else if (rowKind && (token.type === "data" || token.type === 'tableDelimiterMarker' || token.type === 'tableDelimiterFiller')) {
inFirstCellAwaitingPipe = false;

@@ -695,32 +665,18 @@ // First value in cell.

if (lastCell[1] !== 0) {
cell[0] = cell[1]
currentCell = flushCell(
map,
context,
lastCell,
rowKind,
undefined,
currentCell
)
lastCell = [0, 0, 0, 0]
cell[0] = cell[1];
currentCell = flushCell(map, context, lastCell, rowKind, undefined, currentCell);
lastCell = [0, 0, 0, 0];
}
cell[2] = index
cell[2] = index;
}
} else if (token.type === 'tableCellDivider') {
if (inFirstCellAwaitingPipe) {
inFirstCellAwaitingPipe = false
inFirstCellAwaitingPipe = false;
} else {
if (lastCell[1] !== 0) {
cell[0] = cell[1]
currentCell = flushCell(
map,
context,
lastCell,
rowKind,
undefined,
currentCell
)
cell[0] = cell[1];
currentCell = flushCell(map, context, lastCell, rowKind, undefined, currentCell);
}
lastCell = cell
cell = [lastCell[1], index, 0, 0]
lastCell = cell;
cell = [lastCell[1], index, 0, 0];
}

@@ -731,36 +687,21 @@ }

else if (token.type === 'tableHead') {
afterHeadAwaitingFirstBodyRow = true
lastTableEnd = index
} else if (
token.type === 'tableRow' ||
token.type === 'tableDelimiterRow'
) {
lastTableEnd = index
afterHeadAwaitingFirstBodyRow = true;
lastTableEnd = index;
} else if (token.type === 'tableRow' || token.type === 'tableDelimiterRow') {
lastTableEnd = index;
if (lastCell[1] !== 0) {
cell[0] = cell[1]
currentCell = flushCell(
map,
context,
lastCell,
rowKind,
index,
currentCell
)
cell[0] = cell[1];
currentCell = flushCell(map, context, lastCell, rowKind, index, currentCell);
} else if (cell[1] !== 0) {
currentCell = flushCell(map, context, cell, rowKind, index, currentCell)
currentCell = flushCell(map, context, cell, rowKind, index, currentCell);
}
rowKind = 0
} else if (
rowKind &&
(token.type === 'data' ||
token.type === 'tableDelimiterMarker' ||
token.type === 'tableDelimiterFiller')
) {
cell[3] = index
rowKind = 0;
} else if (rowKind && (token.type === "data" || token.type === 'tableDelimiterMarker' || token.type === 'tableDelimiterFiller')) {
cell[3] = index;
}
}
if (lastTableEnd !== 0) {
flushTableEnd(map, context, lastTableEnd, currentTable, currentBody)
flushTableEnd(map, context, lastTableEnd, currentTable, currentBody);
}
map.consume(context.events)
map.consume(context.events);

@@ -770,10 +711,10 @@ // To do: move this into `html`, when events are exposed there.

// That needs updates to `mdast-util-gfm-table`.
index = -1
index = -1;
while (++index < context.events.length) {
const event = context.events[index]
const event = context.events[index];
if (event[0] === 'enter' && event[1].type === 'table') {
event[1]._align = gfmTableAlign(context.events, index)
event[1]._align = gfmTableAlign(context.events, index);
}
}
return events
return events;
}

@@ -796,11 +737,6 @@

// rowKind === 2 ? 'tableDelimiterCell' : 'tableCell'
const groupName =
rowKind === 1
? 'tableHeader'
: rowKind === 2
? 'tableDelimiter'
: 'tableData'
const groupName = rowKind === 1 ? 'tableHeader' : rowKind === 2 ? 'tableDelimiter' : 'tableData';
// `markdown-rs` uses:
// rowKind === 2 ? 'tableDelimiterCellValue' : 'tableCellText'
const valueName = 'tableContent'
const valueName = 'tableContent';

@@ -815,4 +751,4 @@ // Insert an exit for the previous cell, if there is one.

if (range[0] !== 0) {
previousCell.end = Object.assign({}, getPoint(context.events, range[0]))
map.add(range[0], 0, [['exit', previousCell, context]])
previousCell.end = Object.assign({}, getPoint(context.events, range[0]));
map.add(range[0], 0, [['exit', previousCell, context]]);
}

@@ -827,3 +763,3 @@

// ```
const now = getPoint(context.events, range[1])
const now = getPoint(context.events, range[1]);
previousCell = {

@@ -834,4 +770,4 @@ type: groupName,

end: Object.assign({}, now)
}
map.add(range[1], 0, [['enter', previousCell, context]])
};
map.add(range[1], 0, [['enter', previousCell, context]]);

@@ -848,4 +784,4 @@ // Insert text start at first data start and end at last data end, and

if (range[2] !== 0) {
const relatedStart = getPoint(context.events, range[2])
const relatedEnd = getPoint(context.events, range[3])
const relatedStart = getPoint(context.events, range[2]);
const relatedEnd = getPoint(context.events, range[3]);
/** @type {Token} */

@@ -856,20 +792,20 @@ const valueToken = {

end: Object.assign({}, relatedEnd)
}
map.add(range[2], 0, [['enter', valueToken, context]])
};
map.add(range[2], 0, [['enter', valueToken, context]]);
if (rowKind !== 2) {
// Fix positional info on remaining events
const start = context.events[range[2]]
const end = context.events[range[3]]
start[1].end = Object.assign({}, end[1].end)
start[1].type = 'chunkText'
start[1].contentType = 'text'
const start = context.events[range[2]];
const end = context.events[range[3]];
start[1].end = Object.assign({}, end[1].end);
start[1].type = "chunkText";
start[1].contentType = "text";
// Remove if needed.
if (range[3] > range[2] + 1) {
const a = range[2] + 1
const b = range[3] - range[2] - 1
map.add(a, b, [])
const a = range[2] + 1;
const b = range[3] - range[2] - 1;
map.add(a, b, []);
}
}
map.add(range[3] + 1, 0, [['exit', valueToken, context]])
map.add(range[3] + 1, 0, [['exit', valueToken, context]]);
}

@@ -885,7 +821,7 @@

if (rowEnd !== undefined) {
previousCell.end = Object.assign({}, getPoint(context.events, rowEnd))
map.add(rowEnd, 0, [['exit', previousCell, context]])
previousCell = undefined
previousCell.end = Object.assign({}, getPoint(context.events, rowEnd));
map.add(rowEnd, 0, [['exit', previousCell, context]]);
previousCell = undefined;
}
return previousCell
return previousCell;
}

@@ -905,11 +841,11 @@

/** @type {Array<Event>} */
const exits = []
const related = getPoint(context.events, index)
const exits = [];
const related = getPoint(context.events, index);
if (tableBody) {
tableBody.end = Object.assign({}, related)
exits.push(['exit', tableBody, context])
tableBody.end = Object.assign({}, related);
exits.push(['exit', tableBody, context]);
}
table.end = Object.assign({}, related)
exits.push(['exit', table, context])
map.add(index + 1, 0, exits)
table.end = Object.assign({}, related);
exits.push(['exit', table, context]);
map.add(index + 1, 0, exits);
}

@@ -923,5 +859,5 @@

function getPoint(events, index) {
const event = events[index]
const side = event[0] === 'enter' ? 'start' : 'end'
return event[1][side]
}
const event = events[index];
const side = event[0] === 'enter' ? 'start' : 'end';
return event[1][side];
}
{
"name": "micromark-extension-gfm-table",
"version": "2.0.0",
"version": "2.1.0",
"description": "micromark extension to support GFM tables",

@@ -49,12 +49,12 @@ "license": "MIT",

"@types/node": "^20.0.0",
"c8": "^8.0.0",
"c8": "^10.0.0",
"create-gfm-fixtures": "^1.0.0",
"micromark": "^4.0.0",
"micromark-build": "^2.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"prettier": "^3.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.54.0"
"xo": "^0.58.0"
},

@@ -64,3 +64,3 @@ "scripts": {

"build": "tsc --build --clean && tsc --build && type-coverage && micromark-build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api-prod": "node --conditions production test/index.js",

@@ -114,5 +114,6 @@ "test-api-dev": "node --conditions development test/index.js",

"max-depth": "off",
"unicorn/no-this-assignment": "off"
"unicorn/no-this-assignment": "off",
"unicorn/prefer-string-replace-all": "off"
}
}
}

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

* [What is this?](#what-is-this)
* [When to use this](#when-to-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`gfmTable()`](#gfmtable)
* [`gfmTableHtml()`](#gfmtablehtml)
* [Bugs](#bugs)
* [Authoring](#authoring)
* [HTML](#html)
* [CSS](#css)
* [Syntax](#syntax)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When to use this](#when-to-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`gfmTable()`](#gfmtable)
* [`gfmTableHtml()`](#gfmtablehtml)
* [Bugs](#bugs)
* [Authoring](#authoring)
* [HTML](#html)
* [CSS](#css)
* [Syntax](#syntax)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

@@ -140,4 +140,4 @@ ## What is this?

* [GFM tables: escaped escapes are incorrectly treated as
escapes](https://github.com/github/cmark-gfm/issues/277)
* [GFM tables: escaped escapes are incorrectly treated as
escapes](https://github.com/github/cmark-gfm/issues/277)

@@ -412,10 +412,10 @@ ## Authoring

* [`micromark-extension-gfm`][micromark-extension-gfm]
— support all of GFM
* [`mdast-util-gfm-table`][mdast-util-gfm-table]
— support all of GFM in mdast
* [`mdast-util-gfm`][mdast-util-gfm]
— support all of GFM in mdast
* [`remark-gfm`][remark-gfm]
— support all of GFM in remark
* [`micromark-extension-gfm`][micromark-extension-gfm]
— support all of GFM
* [`mdast-util-gfm-table`][mdast-util-gfm-table]
— support all of GFM in mdast
* [`mdast-util-gfm`][mdast-util-gfm]
— support all of GFM in mdast
* [`remark-gfm`][remark-gfm]
— support all of GFM in remark

@@ -422,0 +422,0 @@ ## Contribute

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