micromark-extension-gfm-strikethrough
Advanced tools
Comparing version 2.0.0 to 2.1.0
export {gfmStrikethroughHtml} from './lib/html.js' | ||
export {gfmStrikethrough, type Options} from './lib/syntax.js' | ||
export {gfmStrikethrough} from './lib/syntax.js' | ||
/** | ||
* Configuration (optional). | ||
*/ | ||
export interface Options { | ||
/** | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
*/ | ||
singleTilde?: boolean | null | undefined | ||
} | ||
/** | ||
* Augment. | ||
*/ | ||
declare module 'micromark-util-types' { | ||
/** | ||
* Token types. | ||
*/ | ||
interface TokenTypeMap { | ||
@@ -6,0 +25,0 @@ strikethroughSequence: 'strikethroughSequence' |
/** | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @import {HtmlExtension} from 'micromark-util-types' | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
export function gfmStrikethroughHtml(): HtmlExtension | ||
export type HtmlExtension = import('micromark-util-types').HtmlExtension | ||
export function gfmStrikethroughHtml(): HtmlExtension; | ||
import type { HtmlExtension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @import {HtmlExtension} from 'micromark-util-types' | ||
*/ | ||
@@ -4,0 +4,0 @@ |
@@ -10,23 +10,4 @@ /** | ||
*/ | ||
export function gfmStrikethrough( | ||
options?: Options | null | undefined | ||
): Extension | ||
export type Event = import('micromark-util-types').Event | ||
export type Extension = import('micromark-util-types').Extension | ||
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 | ||
/** | ||
* Configuration (optional). | ||
*/ | ||
export type Options = { | ||
/** | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
*/ | ||
singleTilde?: boolean | null | undefined | ||
} | ||
export function gfmStrikethrough(options?: Options | null | undefined): Extension; | ||
import type { Options } from 'micromark-extension-gfm-strikethrough'; | ||
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').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 | ||
* | ||
* @typedef Options | ||
* Configuration (optional). | ||
* @property {boolean | null | undefined} [singleTilde=true] | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
* @import {Options} from 'micromark-extension-gfm-strikethrough' | ||
* @import {Event, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' | ||
*/ | ||
@@ -38,2 +25,3 @@ | ||
const tokenizer = { | ||
name: 'strikethrough', | ||
tokenize: tokenizeStrikethrough, | ||
@@ -40,0 +28,0 @@ resolveAll: resolveAllStrikethrough |
export {gfmStrikethroughHtml} from './lib/html.js' | ||
export {gfmStrikethrough, type Options} from './lib/syntax.js' | ||
export {gfmStrikethrough} from './lib/syntax.js' | ||
/** | ||
* Configuration (optional). | ||
*/ | ||
export interface Options { | ||
/** | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
*/ | ||
singleTilde?: boolean | null | undefined | ||
} | ||
declare module 'micromark-util-types' { | ||
@@ -5,0 +18,0 @@ interface TokenTypeMap { |
// Note: more types exposed from `index.d.ts`. | ||
export {gfmStrikethroughHtml} from './lib/html.js' | ||
export {gfmStrikethrough} from './lib/syntax.js' | ||
export { gfmStrikethroughHtml } from './lib/html.js'; | ||
export { gfmStrikethrough } from './lib/syntax.js'; |
/** | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @import {HtmlExtension} from 'micromark-util-types' | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
export function gfmStrikethroughHtml(): HtmlExtension | ||
export type HtmlExtension = import('micromark-util-types').HtmlExtension | ||
export function gfmStrikethroughHtml(): HtmlExtension; | ||
import type { HtmlExtension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @import {HtmlExtension} from 'micromark-util-types' | ||
*/ | ||
@@ -17,3 +17,3 @@ | ||
strikethrough() { | ||
this.tag('<del>') | ||
this.tag('<del>'); | ||
} | ||
@@ -23,6 +23,6 @@ }, | ||
strikethrough() { | ||
this.tag('</del>') | ||
this.tag('</del>'); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} |
@@ -10,23 +10,4 @@ /** | ||
*/ | ||
export function gfmStrikethrough( | ||
options?: Options | null | undefined | ||
): Extension | ||
export type Event = import('micromark-util-types').Event | ||
export type Extension = import('micromark-util-types').Extension | ||
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 | ||
/** | ||
* Configuration (optional). | ||
*/ | ||
export type Options = { | ||
/** | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
*/ | ||
singleTilde?: boolean | null | undefined | ||
} | ||
export function gfmStrikethrough(options?: Options | null | undefined): Extension; | ||
import type { Options } from 'micromark-extension-gfm-strikethrough'; | ||
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').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 | ||
* | ||
* @typedef Options | ||
* Configuration (optional). | ||
* @property {boolean | null | undefined} [singleTilde=true] | ||
* Whether to support strikethrough with a single tilde (default: `true`). | ||
* | ||
* Single tildes work on github.com, but are technically prohibited by the | ||
* GFM spec. | ||
* @import {Options} from 'micromark-extension-gfm-strikethrough' | ||
* @import {Event, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' | ||
*/ | ||
import {splice} from 'micromark-util-chunked' | ||
import {classifyCharacter} from 'micromark-util-classify-character' | ||
import {resolveAll} from 'micromark-util-resolve-all' | ||
import { splice } from 'micromark-util-chunked'; | ||
import { classifyCharacter } from 'micromark-util-classify-character'; | ||
import { resolveAll } from 'micromark-util-resolve-all'; | ||
/** | ||
@@ -32,10 +19,11 @@ * Create an extension for `micromark` to enable GFM strikethrough syntax. | ||
export function gfmStrikethrough(options) { | ||
const options_ = options || {} | ||
let single = options_.singleTilde | ||
const options_ = options || {}; | ||
let single = options_.singleTilde; | ||
const tokenizer = { | ||
name: 'strikethrough', | ||
tokenize: tokenizeStrikethrough, | ||
resolveAll: resolveAllStrikethrough | ||
} | ||
}; | ||
if (single === null || single === undefined) { | ||
single = true | ||
single = true; | ||
} | ||
@@ -52,3 +40,3 @@ return { | ||
} | ||
} | ||
}; | ||
@@ -61,3 +49,3 @@ /** | ||
function resolveAllStrikethrough(events, context) { | ||
let index = -1 | ||
let index = -1; | ||
@@ -67,8 +55,4 @@ // Walk through all events. | ||
// Find a token that can close. | ||
if ( | ||
events[index][0] === 'enter' && | ||
events[index][1].type === 'strikethroughSequenceTemporary' && | ||
events[index][1]._close | ||
) { | ||
let open = index | ||
if (events[index][0] === 'enter' && events[index][1].type === 'strikethroughSequenceTemporary' && events[index][1]._close) { | ||
let open = index; | ||
@@ -78,12 +62,7 @@ // Now walk back to find an opener. | ||
// Find a token that can open the closer. | ||
if ( | ||
events[open][0] === 'exit' && | ||
events[open][1].type === 'strikethroughSequenceTemporary' && | ||
events[open][1]._open && | ||
// If the sizes are the same: | ||
events[index][1].end.offset - events[index][1].start.offset === | ||
events[open][1].end.offset - events[open][1].start.offset | ||
) { | ||
events[index][1].type = 'strikethroughSequence' | ||
events[open][1].type = 'strikethroughSequence' | ||
if (events[open][0] === 'exit' && events[open][1].type === 'strikethroughSequenceTemporary' && events[open][1]._open && | ||
// If the sizes are the same: | ||
events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) { | ||
events[index][1].type = 'strikethroughSequence'; | ||
events[open][1].type = 'strikethroughSequence'; | ||
@@ -95,3 +74,3 @@ /** @type {Token} */ | ||
end: Object.assign({}, events[index][1].end) | ||
} | ||
}; | ||
@@ -103,33 +82,18 @@ /** @type {Token} */ | ||
end: Object.assign({}, events[index][1].start) | ||
} | ||
}; | ||
// Opening. | ||
/** @type {Array<Event>} */ | ||
const nextEvents = [ | ||
['enter', strikethrough, context], | ||
['enter', events[open][1], context], | ||
['exit', events[open][1], context], | ||
['enter', text, context] | ||
] | ||
const insideSpan = context.parser.constructs.insideSpan.null | ||
const nextEvents = [['enter', strikethrough, context], ['enter', events[open][1], context], ['exit', events[open][1], context], ['enter', text, context]]; | ||
const insideSpan = context.parser.constructs.insideSpan.null; | ||
if (insideSpan) { | ||
// Between. | ||
splice( | ||
nextEvents, | ||
nextEvents.length, | ||
0, | ||
resolveAll(insideSpan, events.slice(open + 1, index), context) | ||
) | ||
splice(nextEvents, nextEvents.length, 0, resolveAll(insideSpan, events.slice(open + 1, index), context)); | ||
} | ||
// Closing. | ||
splice(nextEvents, nextEvents.length, 0, [ | ||
['exit', text, context], | ||
['enter', events[index][1], context], | ||
['exit', events[index][1], context], | ||
['exit', strikethrough, context] | ||
]) | ||
splice(events, open - 1, index - open + 3, nextEvents) | ||
index = open + nextEvents.length - 2 | ||
break | ||
splice(nextEvents, nextEvents.length, 0, [['exit', text, context], ['enter', events[index][1], context], ['exit', events[index][1], context], ['exit', strikethrough, context]]); | ||
splice(events, open - 1, index - open + 3, nextEvents); | ||
index = open + nextEvents.length - 2; | ||
break; | ||
} | ||
@@ -139,9 +103,9 @@ } | ||
} | ||
index = -1 | ||
index = -1; | ||
while (++index < events.length) { | ||
if (events[index][1].type === 'strikethroughSequenceTemporary') { | ||
events[index][1].type = 'data' | ||
events[index][1].type = "data"; | ||
} | ||
} | ||
return events | ||
return events; | ||
} | ||
@@ -154,17 +118,14 @@ | ||
function tokenizeStrikethrough(effects, ok, nok) { | ||
const previous = this.previous | ||
const events = this.events | ||
let size = 0 | ||
return start | ||
const previous = this.previous; | ||
const events = this.events; | ||
let size = 0; | ||
return start; | ||
/** @type {State} */ | ||
function start(code) { | ||
if ( | ||
previous === 126 && | ||
events[events.length - 1][1].type !== 'characterEscape' | ||
) { | ||
return nok(code) | ||
if (previous === 126 && events[events.length - 1][1].type !== "characterEscape") { | ||
return nok(code); | ||
} | ||
effects.enter('strikethroughSequenceTemporary') | ||
return more(code) | ||
effects.enter('strikethroughSequenceTemporary'); | ||
return more(code); | ||
} | ||
@@ -174,18 +135,18 @@ | ||
function more(code) { | ||
const before = classifyCharacter(previous) | ||
const before = classifyCharacter(previous); | ||
if (code === 126) { | ||
// If this is the third marker, exit. | ||
if (size > 1) return nok(code) | ||
effects.consume(code) | ||
size++ | ||
return more | ||
if (size > 1) return nok(code); | ||
effects.consume(code); | ||
size++; | ||
return more; | ||
} | ||
if (size < 2 && !single) return nok(code) | ||
const token = effects.exit('strikethroughSequenceTemporary') | ||
const after = classifyCharacter(code) | ||
token._open = !after || (after === 2 && Boolean(before)) | ||
token._close = !before || (before === 2 && Boolean(after)) | ||
return ok(code) | ||
if (size < 2 && !single) return nok(code); | ||
const token = effects.exit('strikethroughSequenceTemporary'); | ||
const after = classifyCharacter(code); | ||
token._open = !after || after === 2 && Boolean(before); | ||
token._close = !before || before === 2 && Boolean(after); | ||
return ok(code); | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "micromark-extension-gfm-strikethrough", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "micromark extension to support GFM strikethrough", | ||
@@ -51,13 +51,13 @@ "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", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -67,3 +67,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", | ||
@@ -97,3 +97,5 @@ "test-api-dev": "node --conditions development test/index.js", | ||
"rules": { | ||
"max-depth": "off" | ||
"logical-assignment-operators": "off", | ||
"max-depth": "off", | ||
"unicorn/prefer-at": "off" | ||
}, | ||
@@ -104,3 +106,18 @@ "overrides": [ | ||
"rules": { | ||
"@typescript-eslint/consistent-type-definitions": 0 | ||
"@typescript-eslint/array-type": [ | ||
"error", | ||
{ | ||
"default": "generic" | ||
} | ||
], | ||
"@typescript-eslint/ban-types": [ | ||
"error", | ||
{ | ||
"extendDefaults": true | ||
} | ||
], | ||
"@typescript-eslint/consistent-type-definitions": [ | ||
"error", | ||
"interface" | ||
] | ||
} | ||
@@ -107,0 +124,0 @@ }, |
@@ -15,20 +15,20 @@ # micromark-extension-gfm-strikethrough | ||
* [What is this?](#what-is-this) | ||
* [When to use this](#when-to-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`gfmStrikethrough(options?)`](#gfmstrikethroughoptions) | ||
* [`gfmStrikethroughHtml()`](#gfmstrikethroughhtml) | ||
* [`Options`](#options) | ||
* [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) | ||
* [`gfmStrikethrough(options?)`](#gfmstrikethroughoptions) | ||
* [`gfmStrikethroughHtml()`](#gfmstrikethroughhtml) | ||
* [`Options`](#options) | ||
* [Authoring](#authoring) | ||
* [HTML](#html) | ||
* [CSS](#css) | ||
* [Syntax](#syntax) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
@@ -117,4 +117,4 @@ ## What is this? | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
@@ -143,6 +143,6 @@ ###### Returns | ||
* `singleTilde` (`boolean`, default: `true`) | ||
— whether to support strikethrough with a single tilde. | ||
Single tildes work on github.com, but are technically prohibited by the GFM | ||
spec | ||
* `singleTilde` (`boolean`, default: `true`) | ||
— whether to support strikethrough with a single tilde. | ||
Single tildes work on github.com, but are technically prohibited by the GFM | ||
spec | ||
@@ -212,10 +212,10 @@ ## Authoring | ||
* [`micromark-extension-gfm`][micromark-extension-gfm] | ||
— support all of GFM | ||
* [`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough] | ||
— 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-strikethrough`][mdast-util-gfm-strikethrough] | ||
— 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 | ||
@@ -222,0 +222,0 @@ ## Contribute |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27585
441