🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
12
node_modules/micromark-extension-gfm-strikethrough/dev/index.d.ts
generated
vendored
Normal file
12
node_modules/micromark-extension-gfm-strikethrough/dev/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export {gfmStrikethroughHtml} from './lib/html.js'
|
||||
export {gfmStrikethrough, type Options} from './lib/syntax.js'
|
||||
|
||||
declare module 'micromark-util-types' {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
interface TokenTypeMap {
|
||||
strikethroughSequence: 'strikethroughSequence'
|
||||
strikethroughSequenceTemporary: 'strikethroughSequenceTemporary'
|
||||
strikethrough: 'strikethrough'
|
||||
strikethroughText: 'strikethroughText'
|
||||
}
|
||||
}
|
||||
3
node_modules/micromark-extension-gfm-strikethrough/dev/index.js
generated
vendored
Normal file
3
node_modules/micromark-extension-gfm-strikethrough/dev/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Note: more types exposed from `index.d.ts`.
|
||||
export {gfmStrikethroughHtml} from './lib/html.js'
|
||||
export {gfmStrikethrough} from './lib/syntax.js'
|
||||
11
node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.d.ts
generated
vendored
Normal file
11
node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
|
||||
*/
|
||||
/**
|
||||
* Extension for `micromark` that can be passed in `htmlExtensions`, to
|
||||
* support GFM strikethrough when serializing to HTML.
|
||||
*
|
||||
* @type {HtmlExtension}
|
||||
*/
|
||||
export const gfmStrikethroughHtml: HtmlExtension
|
||||
export type HtmlExtension = import('micromark-util-types').HtmlExtension
|
||||
24
node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.js
generated
vendored
Normal file
24
node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.js
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
|
||||
*/
|
||||
|
||||
// To do: next major: expose function instead of object.
|
||||
|
||||
/**
|
||||
* Extension for `micromark` that can be passed in `htmlExtensions`, to
|
||||
* support GFM strikethrough when serializing to HTML.
|
||||
*
|
||||
* @type {HtmlExtension}
|
||||
*/
|
||||
export const gfmStrikethroughHtml = {
|
||||
enter: {
|
||||
strikethrough() {
|
||||
this.tag('<del>')
|
||||
}
|
||||
},
|
||||
exit: {
|
||||
strikethrough() {
|
||||
this.tag('</del>')
|
||||
}
|
||||
}
|
||||
}
|
||||
31
node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.d.ts
generated
vendored
Normal file
31
node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Create an extension for `micromark` to enable GFM strikethrough syntax.
|
||||
*
|
||||
* @param {Options | null | undefined} [options]
|
||||
* Configuration.
|
||||
* @returns {Extension}
|
||||
* Extension for `micromark` that can be passed in `extensions`, to
|
||||
* enable GFM strikethrough syntax.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* Single tildes work on github.com, but are technically prohibited by the
|
||||
* GFM spec.
|
||||
*/
|
||||
singleTilde?: boolean
|
||||
}
|
||||
197
node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.js
generated
vendored
Normal file
197
node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.js
generated
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
* @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} [singleTilde=true]
|
||||
* Whether to support strikethrough with a single tilde.
|
||||
*
|
||||
* Single tildes work on github.com, but are technically prohibited by the
|
||||
* GFM spec.
|
||||
*/
|
||||
|
||||
import {ok as assert} from 'uvu/assert'
|
||||
import {splice} from 'micromark-util-chunked'
|
||||
import {classifyCharacter} from 'micromark-util-classify-character'
|
||||
import {resolveAll} from 'micromark-util-resolve-all'
|
||||
import {codes} from 'micromark-util-symbol/codes.js'
|
||||
import {constants} from 'micromark-util-symbol/constants.js'
|
||||
import {types} from 'micromark-util-symbol/types.js'
|
||||
|
||||
/**
|
||||
* Create an extension for `micromark` to enable GFM strikethrough syntax.
|
||||
*
|
||||
* @param {Options | null | undefined} [options]
|
||||
* Configuration.
|
||||
* @returns {Extension}
|
||||
* Extension for `micromark` that can be passed in `extensions`, to
|
||||
* enable GFM strikethrough syntax.
|
||||
*/
|
||||
export function gfmStrikethrough(options) {
|
||||
const options_ = options || {}
|
||||
let single = options_.singleTilde
|
||||
const tokenizer = {
|
||||
tokenize: tokenizeStrikethrough,
|
||||
resolveAll: resolveAllStrikethrough
|
||||
}
|
||||
|
||||
if (single === null || single === undefined) {
|
||||
single = true
|
||||
}
|
||||
|
||||
return {
|
||||
text: {[codes.tilde]: tokenizer},
|
||||
insideSpan: {null: [tokenizer]},
|
||||
attentionMarkers: {null: [codes.tilde]}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take events and resolve strikethrough.
|
||||
*
|
||||
* @type {Resolver}
|
||||
*/
|
||||
function resolveAllStrikethrough(events, context) {
|
||||
let index = -1
|
||||
|
||||
// Walk through all events.
|
||||
while (++index < events.length) {
|
||||
// Find a token that can close.
|
||||
if (
|
||||
events[index][0] === 'enter' &&
|
||||
events[index][1].type === 'strikethroughSequenceTemporary' &&
|
||||
events[index][1]._close
|
||||
) {
|
||||
let open = index
|
||||
|
||||
// Now walk back to find an opener.
|
||||
while (open--) {
|
||||
// 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'
|
||||
|
||||
/** @type {Token} */
|
||||
const strikethrough = {
|
||||
type: 'strikethrough',
|
||||
start: Object.assign({}, events[open][1].start),
|
||||
end: Object.assign({}, events[index][1].end)
|
||||
}
|
||||
|
||||
/** @type {Token} */
|
||||
const text = {
|
||||
type: 'strikethroughText',
|
||||
start: Object.assign({}, events[open][1].end),
|
||||
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
|
||||
|
||||
if (insideSpan) {
|
||||
// Between.
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index = -1
|
||||
|
||||
while (++index < events.length) {
|
||||
if (events[index][1].type === 'strikethroughSequenceTemporary') {
|
||||
events[index][1].type = types.data
|
||||
}
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {TokenizeContext}
|
||||
* @type {Tokenizer}
|
||||
*/
|
||||
function tokenizeStrikethrough(effects, ok, nok) {
|
||||
const previous = this.previous
|
||||
const events = this.events
|
||||
let size = 0
|
||||
|
||||
return start
|
||||
|
||||
/** @type {State} */
|
||||
function start(code) {
|
||||
assert(code === codes.tilde, 'expected `~`')
|
||||
|
||||
if (
|
||||
previous === codes.tilde &&
|
||||
events[events.length - 1][1].type !== types.characterEscape
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.enter('strikethroughSequenceTemporary')
|
||||
return more(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function more(code) {
|
||||
const before = classifyCharacter(previous)
|
||||
|
||||
if (code === codes.tilde) {
|
||||
// If this is the third marker, exit.
|
||||
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 === constants.attentionSideAfter && Boolean(before))
|
||||
token._close =
|
||||
!before || (before === constants.attentionSideAfter && Boolean(after))
|
||||
return ok(code)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue