planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
exports.enter = {strikethrough: onenterstrikethrough}
exports.exit = {strikethrough: onexitstrikethrough}
function onenterstrikethrough() {
this.tag('<del>')
}
function onexitstrikethrough() {
this.tag('</del>')
}

View File

@@ -0,0 +1,160 @@
module.exports = create
var classifyCharacter = require('micromark/dist/util/classify-character')
var chunkedSplice = require('micromark/dist/util/chunked-splice')
var resolveAll = require('micromark/dist/util/resolve-all')
var shallow = require('micromark/dist/util/shallow')
function create(options) {
var settings = options || {}
var single = settings.singleTilde
var tokenizer = {
tokenize: tokenizeStrikethrough,
resolveAll: resolveAllStrikethrough
}
if (single === null || single === undefined) {
single = true
}
return {text: {126: tokenizer}, insideSpan: {null: tokenizer}}
// Take events and resolve strikethrough.
function resolveAllStrikethrough(events, context) {
var index = -1
var strikethrough
var text
var open
var nextEvents
// 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
) {
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'
strikethrough = {
type: 'strikethrough',
start: shallow(events[open][1].start),
end: shallow(events[index][1].end)
}
text = {
type: 'strikethroughText',
start: shallow(events[open][1].end),
end: shallow(events[index][1].start)
}
// Opening.
nextEvents = [
['enter', strikethrough, context],
['enter', events[open][1], context],
['exit', events[open][1], context],
['enter', text, context]
]
// Between.
chunkedSplice(
nextEvents,
nextEvents.length,
0,
resolveAll(
context.parser.constructs.insideSpan.null,
events.slice(open + 1, index),
context
)
)
// Closing.
chunkedSplice(nextEvents, nextEvents.length, 0, [
['exit', text, context],
['enter', events[index][1], context],
['exit', events[index][1], context],
['exit', strikethrough, context]
])
chunkedSplice(events, open - 1, index - open + 3, nextEvents)
index = open + nextEvents.length - 2
break
}
}
}
}
return removeRemainingSequences(events)
}
function removeRemainingSequences(events) {
var index = -1
var length = events.length
while (++index < length) {
if (events[index][1].type === 'strikethroughSequenceTemporary') {
events[index][1].type = 'data'
}
}
return events
}
function tokenizeStrikethrough(effects, ok, nok) {
var previous = this.previous
var events = this.events
var size = 0
return start
function start(code) {
if (
code !== 126 ||
(previous === 126 &&
events[events.length - 1][1].type !== 'characterEscape')
) {
return nok(code)
}
effects.enter('strikethroughSequenceTemporary')
return more(code)
}
function more(code) {
var before = classifyCharacter(previous)
var token
var after
if (code === 126) {
// 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)
token = effects.exit('strikethroughSequenceTemporary')
after = classifyCharacter(code)
token._open = !after || (after === 2 && before)
token._close = !before || (before === 2 && after)
return ok(code)
}
}
}

View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 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.

View File

@@ -0,0 +1,81 @@
{
"name": "micromark-extension-gfm-strikethrough",
"version": "0.6.5",
"description": "micromark extension to support GFM strikethrough",
"license": "MIT",
"keywords": [
"micromark",
"micromark-extension",
"strikethrough",
"strike",
"through",
"del",
"delete",
"deletion",
"gfm",
"markdown",
"unified"
],
"repository": "micromark/micromark-extension-gfm-strikethrough",
"bugs": "https://github.com/micromark/micromark-extension-gfm-strikethrough/issues",
"funding": {
"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)"
],
"types": "types/index.d.ts",
"files": [
"types/*.d.ts",
"lib/",
"index.js",
"html.js"
],
"dependencies": {
"micromark": "~2.11.0"
},
"devDependencies": {
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test-types": "dtslint types",
"test": "npm run format && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"types"
]
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

View File

@@ -0,0 +1,135 @@
# micromark-extension-gfm-strikethrough
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
**[micromark][]** extension to support GitHub flavored markdown
[strikethrough][] (~~like this~~).
This syntax extension matches either the GFM spec (only two tildes work) or
github.com (both one or two tildes, when they match, work).
This package provides the low-level modules for integrating with the micromark
tokenizer and the micromark HTML compiler.
You probably shouldnt use this package directly, but instead use
[`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough] with
**[mdast][]**.
## Install
[npm][]:
```sh
npm install micromark-extension-gfm-strikethrough
```
## API
### `html`
### `syntax(options?)`
> Note: `syntax` is the default export of this module, `html` is available at
> `micromark-extension-gfm-strikethrough/html`.
Support strikethrough (~~like this~~).
The export of `syntax` is a function that can be called with options and returns
an extension for the micromark parser (to tokenize strikethrough; can be passed
in `extensions`).
The export of `html` is an extension for the default HTML compiler (to compile
as `<del>` elements; can be passed in `htmlExtensions`).
##### `options`
###### `options.singleTilde`
Whether to support strikethrough with a single tilde (`boolean`, default:
`true`).
Single tildes work on github.com, but are technically prohibited by the GFM
spec.
## Related
* [`remarkjs/remark`][remark]
— markdown processor powered by plugins
* [`micromark/micromark`][micromark]
— the smallest commonmark-compliant markdown parser that exists
* [`syntax-tree/mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough]
— mdast utility to support strikethrough
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
— mdast parser using `micromark` to create mdast from markdown
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
— mdast serializer to create markdown from mdast
## Contribute
See [`contributing.md` in `micromark/.github`][contributing] 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, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark-extension-gfm-strikethrough/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark-extension-gfm-strikethrough/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-strikethrough.svg
[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-strikethrough
[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-strikethrough.svg
[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-strikethrough
[size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-extension-gfm-strikethrough.svg
[size]: https://bundlephobia.com/result?p=micromark-extension-gfm-strikethrough
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[npm]: https://docs.npmjs.com/cli/install
[license]: license
[author]: https://wooorm.com
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[micromark]: https://github.com/micromark/micromark
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
[remark]: https://github.com/remarkjs/remark
[mdast]: https://github.com/syntax-tree/mdast
[mdast-util-gfm-strikethrough]: https://github.com/syntax-tree/mdast-util-gfm-strikethrough
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-

View File

@@ -0,0 +1,8 @@
import {HtmlExtension} from 'micromark/dist/shared-types'
/**
* The export of `html` is an extension for the default HTML compiler (to
* compile as `<del>` elements; can be passed in `htmlExtensions`).
*/
declare const html: HtmlExtension
export = html

View File

@@ -0,0 +1,26 @@
// TypeScript Version: 4.0
import {SyntaxExtension} from 'micromark/dist/shared-types'
/**
* Support strikethrough (~~like this~~). The export of `syntax` is a function
* that can be called with options and returns an extension for the micromark
* parser (to tokenize strikethrough; can be passed in `extensions`).
*/
declare function syntax(
options?: syntax.GfmStrikethroughOptions
): SyntaxExtension
declare namespace syntax {
interface GfmStrikethroughOptions {
/**
* Whether to support strikethrough with a single tilde. Single tildes work
* on github.com, but are technically prohibited by the GFM spec.
*
* @default true
*/
singleTilde?: boolean
}
}
export = syntax