This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @import {Event} from 'micromark-util-types'
|
||||
*/
|
||||
/**
|
||||
* @typedef {[number, number, Array<Event>]} Change
|
||||
* @typedef {[number, number, number]} Jump
|
||||
*/
|
||||
/**
|
||||
* Tracks a bunch of edits.
|
||||
*
|
||||
* Port of `edit_map.rs` from `markdown-rs`:
|
||||
* <https://github.com/wooorm/markdown-rs/blob/1506572f/src/util/edit_map.rs>.
|
||||
*
|
||||
* Deal with several changes in events, batching them together.
|
||||
*
|
||||
* Preferably, changes should be kept to a minimum.
|
||||
* Sometimes, it’s needed to change the list of events, because parsing can be
|
||||
* messy, and it helps to expose a cleaner interface of events to the compiler
|
||||
* and other users.
|
||||
* It can also help to merge many adjacent similar events.
|
||||
* And, in other cases, it’s needed to parse subcontent: pass some events
|
||||
* through another tokenizer and inject the result.
|
||||
*/
|
||||
export class EditMap {
|
||||
/**
|
||||
* Changes by index, so `add` does not need to scan `map` (which is
|
||||
* quadratic for documents with many edits at different places).
|
||||
*
|
||||
* @type {Map<number, Change>}
|
||||
*/
|
||||
index: Map<number, Change>;
|
||||
/**
|
||||
* Record of changes.
|
||||
*
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
map: Array<Change>;
|
||||
/**
|
||||
* Create an edit: a remove and/or add at a certain place.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
add(index: number, remove: number, add: Array<Event>): undefined;
|
||||
/**
|
||||
* Create an edit: but insert `add` before existing additions, instead of
|
||||
* after them.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
addBefore(index: number, remove: number, add: Array<Event>): undefined;
|
||||
/**
|
||||
* Done, change the events.
|
||||
*
|
||||
* @param {Array<Event>} events
|
||||
* List of events to apply the edits to.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
consume(events: Array<Event>): undefined;
|
||||
}
|
||||
export type Change = [number, number, Array<Event>];
|
||||
export type Jump = [number, number, number];
|
||||
import type { Event } from 'micromark-util-types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IAQI;;;;;OAKG;IACH,OAFU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEP;IAEtB;;;;OAIG;IACH,KAFU,KAAK,CAAC,MAAM,CAAC,CAEV;IAGf;;;;;;;;;;;OAWG;IACH,WATW,MAAM,UAEN,MAAM,OAEN,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CAKrB;IAED;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,UAEN,MAAM,OAEN,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CAKrB;IAED;;;;;;;OAOG;IACH,gBALW,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CA4DrB;CACF;qBA/IY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;mBAC9B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;2BALb,sBAAsB"}
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
/**
|
||||
* @import {Event} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {[number, number, Array<Event>]} Change
|
||||
* @typedef {[number, number, number]} Jump
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tracks a bunch of edits.
|
||||
*
|
||||
* Port of `edit_map.rs` from `markdown-rs`:
|
||||
* <https://github.com/wooorm/markdown-rs/blob/1506572f/src/util/edit_map.rs>.
|
||||
*
|
||||
* Deal with several changes in events, batching them together.
|
||||
*
|
||||
* Preferably, changes should be kept to a minimum.
|
||||
* Sometimes, it’s needed to change the list of events, because parsing can be
|
||||
* messy, and it helps to expose a cleaner interface of events to the compiler
|
||||
* and other users.
|
||||
* It can also help to merge many adjacent similar events.
|
||||
* And, in other cases, it’s needed to parse subcontent: pass some events
|
||||
* through another tokenizer and inject the result.
|
||||
*/
|
||||
export class EditMap {
|
||||
/**
|
||||
* Create a new edit map.
|
||||
*
|
||||
* @returns
|
||||
* New instance.
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* Changes by index, so `add` does not need to scan `map` (which is
|
||||
* quadratic for documents with many edits at different places).
|
||||
*
|
||||
* @type {Map<number, Change>}
|
||||
*/
|
||||
this.index = new Map()
|
||||
|
||||
/**
|
||||
* Record of changes.
|
||||
*
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
this.map = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit: a remove and/or add at a certain place.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
add(index, remove, add) {
|
||||
addImplementation(this, index, remove, add, false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit: but insert `add` before existing additions, instead of
|
||||
* after them.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
addBefore(index, remove, add) {
|
||||
addImplementation(this, index, remove, add, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Done, change the events.
|
||||
*
|
||||
* @param {Array<Event>} events
|
||||
* List of events to apply the edits to.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
consume(events) {
|
||||
this.map.sort(function (a, b) {
|
||||
return a[0] - b[0]
|
||||
})
|
||||
|
||||
if (this.map.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// To do: if links are added in events, like they are in `markdown-rs`,
|
||||
// this is needed.
|
||||
// // Calculate jumps: where items in the current list move to.
|
||||
// /** @type {Array<Jump>} */
|
||||
// const jumps = []
|
||||
// let index = 0
|
||||
// let addAcc = 0
|
||||
// let removeAcc = 0
|
||||
// while (index < this.map.length) {
|
||||
// const [at, remove, add] = this.map[index]
|
||||
// removeAcc += remove
|
||||
// addAcc += add.length
|
||||
// jumps.push([at, removeAcc, addAcc])
|
||||
// index += 1
|
||||
// }
|
||||
//
|
||||
// shiftLinks(events, jumps)
|
||||
|
||||
let index = this.map.length
|
||||
/** @type {Array<Array<Event>>} */
|
||||
const vecs = []
|
||||
while (index > 0) {
|
||||
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]
|
||||
}
|
||||
|
||||
vecs.push(events.slice())
|
||||
events.length = 0
|
||||
|
||||
let slice = vecs.pop()
|
||||
|
||||
while (slice) {
|
||||
for (const element of slice) {
|
||||
events.push(element)
|
||||
}
|
||||
|
||||
slice = vecs.pop()
|
||||
}
|
||||
|
||||
// Truncate everything.
|
||||
this.map.length = 0
|
||||
this.index.clear()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit.
|
||||
*
|
||||
* @param {EditMap} editMap
|
||||
* Edit map to apply to.
|
||||
* @param {number} at
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @param {boolean} before
|
||||
* Insert `add` before existing additions at `at`, instead of after them.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function addImplementation(editMap, at, remove, add, before) {
|
||||
if (remove === 0 && add.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const existing = editMap.index.get(at)
|
||||
|
||||
if (existing) {
|
||||
existing[1] += remove
|
||||
|
||||
if (before) {
|
||||
add.push(...existing[2])
|
||||
existing[2] = add
|
||||
} else {
|
||||
existing[2].push(...add)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/** @type {Change} */
|
||||
const change = [at, remove, add]
|
||||
editMap.map.push(change)
|
||||
editMap.index.set(at, change)
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Shift `previous` and `next` links according to `jumps`.
|
||||
// *
|
||||
// * This fixes links in case there are events removed or added between them.
|
||||
// *
|
||||
// * @param {Array<Event>} events
|
||||
// * @param {Array<Jump>} jumps
|
||||
// */
|
||||
// function shiftLinks(events, jumps) {
|
||||
// let jumpIndex = 0
|
||||
// let index = 0
|
||||
// let add = 0
|
||||
// let rm = 0
|
||||
|
||||
// while (index < events.length) {
|
||||
// const rmCurr = rm
|
||||
|
||||
// while (jumpIndex < jumps.length && jumps[jumpIndex][0] <= index) {
|
||||
// add = jumps[jumpIndex][2]
|
||||
// rm = jumps[jumpIndex][1]
|
||||
// jumpIndex += 1
|
||||
// }
|
||||
|
||||
// // Ignore items that will be removed.
|
||||
// if (rm > rmCurr) {
|
||||
// index += rm - rmCurr
|
||||
// } else {
|
||||
// // ?
|
||||
// // if let Some(link) = &events[index].link {
|
||||
// // if let Some(next) = link.next {
|
||||
// // events[next].link.as_mut().unwrap().previous = Some(index + add - rm);
|
||||
// // while jumpIndex < jumps.len() && jumps[jumpIndex].0 <= next {
|
||||
// // add = jumps[jumpIndex].2;
|
||||
// // rm = jumps[jumpIndex].1;
|
||||
// // jumpIndex += 1;
|
||||
// // }
|
||||
// // events[index].link.as_mut().unwrap().next = Some(next + add - rm);
|
||||
// // index = next;
|
||||
// // continue;
|
||||
// // }
|
||||
// // }
|
||||
// index += 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @import {Event} from 'micromark-util-types'
|
||||
*/
|
||||
/**
|
||||
* @typedef {[number, number, Array<Event>]} Change
|
||||
* @typedef {[number, number, number]} Jump
|
||||
*/
|
||||
/**
|
||||
* Tracks a bunch of edits.
|
||||
*
|
||||
* Port of `edit_map.rs` from `markdown-rs`:
|
||||
* <https://github.com/wooorm/markdown-rs/blob/1506572f/src/util/edit_map.rs>.
|
||||
*
|
||||
* Deal with several changes in events, batching them together.
|
||||
*
|
||||
* Preferably, changes should be kept to a minimum.
|
||||
* Sometimes, it’s needed to change the list of events, because parsing can be
|
||||
* messy, and it helps to expose a cleaner interface of events to the compiler
|
||||
* and other users.
|
||||
* It can also help to merge many adjacent similar events.
|
||||
* And, in other cases, it’s needed to parse subcontent: pass some events
|
||||
* through another tokenizer and inject the result.
|
||||
*/
|
||||
export class EditMap {
|
||||
/**
|
||||
* Changes by index, so `add` does not need to scan `map` (which is
|
||||
* quadratic for documents with many edits at different places).
|
||||
*
|
||||
* @type {Map<number, Change>}
|
||||
*/
|
||||
index: Map<number, Change>;
|
||||
/**
|
||||
* Record of changes.
|
||||
*
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
map: Array<Change>;
|
||||
/**
|
||||
* Create an edit: a remove and/or add at a certain place.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
add(index: number, remove: number, add: Array<Event>): undefined;
|
||||
/**
|
||||
* Create an edit: but insert `add` before existing additions, instead of
|
||||
* after them.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
addBefore(index: number, remove: number, add: Array<Event>): undefined;
|
||||
/**
|
||||
* Done, change the events.
|
||||
*
|
||||
* @param {Array<Event>} events
|
||||
* List of events to apply the edits to.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
consume(events: Array<Event>): undefined;
|
||||
}
|
||||
export type Change = [number, number, Array<Event>];
|
||||
export type Jump = [number, number, number];
|
||||
import type { Event } from 'micromark-util-types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IAQI;;;;;OAKG;IACH,OAFU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEP;IAEtB;;;;OAIG;IACH,KAFU,KAAK,CAAC,MAAM,CAAC,CAEV;IAGf;;;;;;;;;;;OAWG;IACH,WATW,MAAM,UAEN,MAAM,OAEN,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CAKrB;IAED;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,UAEN,MAAM,OAEN,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CAKrB;IAED;;;;;;;OAOG;IACH,gBALW,KAAK,CAAC,KAAK,CAAC,GAEV,SAAS,CA4DrB;CACF;qBA/IY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;mBAC9B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;2BALb,sBAAsB"}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* @import {Event} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {[number, number, Array<Event>]} Change
|
||||
* @typedef {[number, number, number]} Jump
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tracks a bunch of edits.
|
||||
*
|
||||
* Port of `edit_map.rs` from `markdown-rs`:
|
||||
* <https://github.com/wooorm/markdown-rs/blob/1506572f/src/util/edit_map.rs>.
|
||||
*
|
||||
* Deal with several changes in events, batching them together.
|
||||
*
|
||||
* Preferably, changes should be kept to a minimum.
|
||||
* Sometimes, it’s needed to change the list of events, because parsing can be
|
||||
* messy, and it helps to expose a cleaner interface of events to the compiler
|
||||
* and other users.
|
||||
* It can also help to merge many adjacent similar events.
|
||||
* And, in other cases, it’s needed to parse subcontent: pass some events
|
||||
* through another tokenizer and inject the result.
|
||||
*/
|
||||
export class EditMap {
|
||||
/**
|
||||
* Create a new edit map.
|
||||
*
|
||||
* @returns
|
||||
* New instance.
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* Changes by index, so `add` does not need to scan `map` (which is
|
||||
* quadratic for documents with many edits at different places).
|
||||
*
|
||||
* @type {Map<number, Change>}
|
||||
*/
|
||||
this.index = new Map();
|
||||
|
||||
/**
|
||||
* Record of changes.
|
||||
*
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
this.map = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit: a remove and/or add at a certain place.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
add(index, remove, add) {
|
||||
addImplementation(this, index, remove, add, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit: but insert `add` before existing additions, instead of
|
||||
* after them.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
addBefore(index, remove, add) {
|
||||
addImplementation(this, index, remove, add, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Done, change the events.
|
||||
*
|
||||
* @param {Array<Event>} events
|
||||
* List of events to apply the edits to.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
consume(events) {
|
||||
this.map.sort(function (a, b) {
|
||||
return a[0] - b[0];
|
||||
});
|
||||
if (this.map.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// To do: if links are added in events, like they are in `markdown-rs`,
|
||||
// this is needed.
|
||||
// // Calculate jumps: where items in the current list move to.
|
||||
// /** @type {Array<Jump>} */
|
||||
// const jumps = []
|
||||
// let index = 0
|
||||
// let addAcc = 0
|
||||
// let removeAcc = 0
|
||||
// while (index < this.map.length) {
|
||||
// const [at, remove, add] = this.map[index]
|
||||
// removeAcc += remove
|
||||
// addAcc += add.length
|
||||
// jumps.push([at, removeAcc, addAcc])
|
||||
// index += 1
|
||||
// }
|
||||
//
|
||||
// shiftLinks(events, jumps)
|
||||
|
||||
let index = this.map.length;
|
||||
/** @type {Array<Array<Event>>} */
|
||||
const vecs = [];
|
||||
while (index > 0) {
|
||||
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];
|
||||
}
|
||||
vecs.push(events.slice());
|
||||
events.length = 0;
|
||||
let slice = vecs.pop();
|
||||
while (slice) {
|
||||
for (const element of slice) {
|
||||
events.push(element);
|
||||
}
|
||||
slice = vecs.pop();
|
||||
}
|
||||
|
||||
// Truncate everything.
|
||||
this.map.length = 0;
|
||||
this.index.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an edit.
|
||||
*
|
||||
* @param {EditMap} editMap
|
||||
* Edit map to apply to.
|
||||
* @param {number} at
|
||||
* Index at which to apply the edit.
|
||||
* @param {number} remove
|
||||
* Count of items to remove at the index.
|
||||
* @param {Array<Event>} add
|
||||
* Items to add at the index.
|
||||
* @param {boolean} before
|
||||
* Insert `add` before existing additions at `at`, instead of after them.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function addImplementation(editMap, at, remove, add, before) {
|
||||
if (remove === 0 && add.length === 0) {
|
||||
return;
|
||||
}
|
||||
const existing = editMap.index.get(at);
|
||||
if (existing) {
|
||||
existing[1] += remove;
|
||||
if (before) {
|
||||
add.push(...existing[2]);
|
||||
existing[2] = add;
|
||||
} else {
|
||||
existing[2].push(...add);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** @type {Change} */
|
||||
const change = [at, remove, add];
|
||||
editMap.map.push(change);
|
||||
editMap.index.set(at, change);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Shift `previous` and `next` links according to `jumps`.
|
||||
// *
|
||||
// * This fixes links in case there are events removed or added between them.
|
||||
// *
|
||||
// * @param {Array<Event>} events
|
||||
// * @param {Array<Jump>} jumps
|
||||
// */
|
||||
// function shiftLinks(events, jumps) {
|
||||
// let jumpIndex = 0
|
||||
// let index = 0
|
||||
// let add = 0
|
||||
// let rm = 0
|
||||
|
||||
// while (index < events.length) {
|
||||
// const rmCurr = rm
|
||||
|
||||
// while (jumpIndex < jumps.length && jumps[jumpIndex][0] <= index) {
|
||||
// add = jumps[jumpIndex][2]
|
||||
// rm = jumps[jumpIndex][1]
|
||||
// jumpIndex += 1
|
||||
// }
|
||||
|
||||
// // Ignore items that will be removed.
|
||||
// if (rm > rmCurr) {
|
||||
// index += rm - rmCurr
|
||||
// } else {
|
||||
// // ?
|
||||
// // if let Some(link) = &events[index].link {
|
||||
// // if let Some(next) = link.next {
|
||||
// // events[next].link.as_mut().unwrap().previous = Some(index + add - rm);
|
||||
// // while jumpIndex < jumps.len() && jumps[jumpIndex].0 <= next {
|
||||
// // add = jumps[jumpIndex].2;
|
||||
// // rm = jumps[jumpIndex].1;
|
||||
// // jumpIndex += 1;
|
||||
// // }
|
||||
// // events[index].link.as_mut().unwrap().next = Some(next + add - rm);
|
||||
// // index = next;
|
||||
// // continue;
|
||||
// // }
|
||||
// // }
|
||||
// index += 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "micromark-util-edit-map",
|
||||
"version": "1.0.0",
|
||||
"description": "micromark utility to batch changes to lists of events",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"micromark",
|
||||
"util",
|
||||
"utility",
|
||||
"edit",
|
||||
"map",
|
||||
"splice"
|
||||
],
|
||||
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-edit-map",
|
||||
"bugs": "https://github.com/micromark/micromark/issues",
|
||||
"funding": [
|
||||
{
|
||||
"type": "GitHub Sponsors",
|
||||
"url": "https://github.com/sponsors/unifiedjs"
|
||||
},
|
||||
{
|
||||
"type": "OpenCollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
],
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dev/",
|
||||
"index.d.ts.map",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"exports": {
|
||||
"development": "./dev/index.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"micromark-util-types": "^2.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "micromark-build"
|
||||
}
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
# micromark-util-edit-map
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][bundle-size-badge]][bundle-size]
|
||||
[![Sponsors][sponsors-badge]][opencollective]
|
||||
[![Backers][backers-badge]][opencollective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
[micromark][] utility to batch changes to lists of events.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`EditMap()`](#editmap)
|
||||
* [`EditMap#add(index, remove, add)`](#editmapaddindex-remove-add)
|
||||
* [`EditMap#addBefore(index, remove, add)`](#editmapaddbeforeindex-remove-add)
|
||||
* [`EditMap#consume(events)`](#editmapconsumeevents)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Security](#security)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This package exposes an algorithm to batch changes to lists of events,
|
||||
needed when authoring complex resolvers, such as for tables or lists.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
This package is only useful when you are making your own micromark extensions
|
||||
that need to change many places in lists of events,
|
||||
such as injecting the result of parsing subcontent,
|
||||
or cleaning up how a construct is represented.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 16+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install micromark-util-edit-map
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {EditMap} from 'https://esm.sh/micromark-util-edit-map@1'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {EditMap} from 'https://esm.sh/micromark-util-edit-map@1?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
/**
|
||||
* @import {Event} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {EditMap} from 'micromark-util-edit-map'
|
||||
|
||||
/** @type {Array<Event>} */
|
||||
const events = [] // Assume this is filled.
|
||||
|
||||
const editMap = new EditMap()
|
||||
|
||||
editMap.add(1, 0, [['enter', events[2][1], events[2][2]]])
|
||||
editMap.add(2, 1, [])
|
||||
|
||||
editMap.consume(events)
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This module exports the identifier [`EditMap`][api-edit-map].
|
||||
There is no default export.
|
||||
|
||||
### `EditMap()`
|
||||
|
||||
Create a new edit map.
|
||||
|
||||
###### Returns
|
||||
|
||||
New instance (`EditMap`).
|
||||
|
||||
### `EditMap#add(index, remove, add)`
|
||||
|
||||
Create an edit: a remove and/or add at a certain place.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `index` (`number`)
|
||||
— index at which to apply the edit
|
||||
* `remove` (`number`)
|
||||
— count of items to remove at the index
|
||||
* `add` (`Array<Event>`)
|
||||
— items to add at the index
|
||||
|
||||
###### Returns
|
||||
|
||||
Nothing (`undefined`).
|
||||
|
||||
### `EditMap#addBefore(index, remove, add)`
|
||||
|
||||
Create an edit: but insert `add` before existing additions at `index`,
|
||||
instead of after them.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `index` (`number`)
|
||||
— index at which to apply the edit
|
||||
* `remove` (`number`)
|
||||
— count of items to remove at the index
|
||||
* `add` (`Array<Event>`)
|
||||
— items to add at the index
|
||||
|
||||
###### Returns
|
||||
|
||||
Nothing (`undefined`).
|
||||
|
||||
### `EditMap#consume(events)`
|
||||
|
||||
Done, change the events.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `events` (`Array<Event>`)
|
||||
— list of events to apply the edits to
|
||||
|
||||
###### Returns
|
||||
|
||||
Nothing (`undefined`).
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports no additional types.
|
||||
|
||||
## Compatibility
|
||||
|
||||
Projects maintained by the unified collective are compatible with maintained
|
||||
versions of Node.js.
|
||||
|
||||
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-util-edit-map@1`, compatible with Node.js 16.
|
||||
This package works with `micromark@4`.
|
||||
|
||||
## Security
|
||||
|
||||
This package is safe.
|
||||
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
|
||||
submit a security report.
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
|
||||
to get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organisation, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[api-edit-map]: #editmap
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[build]: https://github.com/micromark/micromark/actions
|
||||
|
||||
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
|
||||
|
||||
[bundle-size]: https://bundlejs.com/?q=micromark-util-edit-map
|
||||
|
||||
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-edit-map
|
||||
|
||||
[chat]: https://github.com/micromark/micromark/discussions
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
|
||||
|
||||
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
|
||||
|
||||
[coverage]: https://codecov.io/github/micromark/micromark
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/micromark-util-edit-map
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-edit-map.svg
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[health]: https://github.com/micromark/.github
|
||||
|
||||
[license]: https://github.com/micromark/micromark/blob/main/license
|
||||
|
||||
[micromark]: https://github.com/micromark/micromark
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[opencollective]: https://opencollective.com/unified
|
||||
|
||||
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[support]: https://github.com/micromark/.github/blob/main/support.md
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
Reference in New Issue
Block a user