micromark-extension-gfm-strikethrough
Advanced tools
Comparing version 0.6.5 to 1.0.0
165
index.js
@@ -1,160 +0,5 @@ | ||
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) | ||
} | ||
} | ||
} | ||
/** | ||
* @typedef {import('./lib/syntax.js').Options} Options | ||
*/ | ||
export {gfmStrikethroughHtml} from './lib/html.js' | ||
export {gfmStrikethrough} from './lib/syntax.js' |
{ | ||
"name": "micromark-extension-gfm-strikethrough", | ||
"version": "0.6.5", | ||
"version": "1.0.0", | ||
"description": "micromark extension to support GFM strikethrough", | ||
@@ -29,34 +29,44 @@ "license": "MIT", | ||
], | ||
"types": "types/index.d.ts", | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"types/*.d.ts", | ||
"dev/", | ||
"lib/", | ||
"index.js", | ||
"html.js" | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"exports": { | ||
"development": "./dev/index.js", | ||
"default": "./index.js" | ||
}, | ||
"dependencies": { | ||
"micromark": "~2.11.0" | ||
"micromark-util-chunked": "^1.0.0", | ||
"micromark-util-classify-character": "^1.0.0", | ||
"micromark-util-resolve-all": "^1.0.0", | ||
"micromark-util-symbol": "^1.0.0", | ||
"micromark-util-types": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"dtslint": "^4.0.0", | ||
"nyc": "^15.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"micromark": "^3.0.0", | ||
"micromark-build": "^1.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"xo": "^0.38.0" | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.40.0" | ||
}, | ||
"scripts": { | ||
"build": "rimraf \"dev/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage && micromark-build", | ||
"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" | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test/index.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -72,6 +82,5 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"types" | ||
] | ||
"rules": { | ||
"unicorn/prefer-node-protocol": "off" | ||
} | ||
}, | ||
@@ -82,3 +91,9 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -11,3 +11,3 @@ # micromark-extension-gfm-strikethrough | ||
**[micromark][]** extension to support GitHub flavored markdown | ||
**[micromark][]** extension to support GitHub flavored markdown (GFM) | ||
[strikethrough][] (~~like this~~). | ||
@@ -17,11 +17,13 @@ This syntax extension matches either the GFM spec (only two tildes work) or | ||
This package provides the low-level modules for integrating with the micromark | ||
tokenizer and the micromark HTML compiler. | ||
## When to use this | ||
You probably shouldn’t use this package directly, but instead use | ||
[`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough] with | ||
**[mdast][]**. | ||
You should probably use [`micromark-extension-gfm`][micromark-extension-gfm] | ||
instead, which combines this package with other GFM features. | ||
Alternatively, if you don’t want all of GFM, use this package. | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -33,17 +35,46 @@ | ||
## Use | ||
```js | ||
import {micromark} from 'micromark' | ||
import { | ||
gfmStrikethrough, | ||
gfmStrikethroughHtml | ||
} from 'micromark-extension-gfm-strikethrough' | ||
const output = micromark('Some ~strikethrough~.', { | ||
extensions: [gfmStrikethrough()], | ||
htmlExtensions: [gfmStrikethroughHtml] | ||
}) | ||
console.log(output) | ||
``` | ||
Yields: | ||
```html | ||
<p>Some <del>strikethrough</del></p>. | ||
``` | ||
## API | ||
### `html` | ||
This package exports the following identifiers: `gfmStrikethrough`, | ||
`gfmStrikethroughHtml`. | ||
There is no default export. | ||
### `syntax(options?)` | ||
The export map supports the endorsed | ||
[`development` condition](https://nodejs.org/api/packages.html#packages_resolving_user_conditions). | ||
Run `node --conditions development module.js` to get instrumented dev code. | ||
Without this condition, production code is loaded. | ||
> Note: `syntax` is the default export of this module, `html` is available at | ||
> `micromark-extension-gfm-strikethrough/html`. | ||
### `gfmStrikethrough(options?)` | ||
### `gfmStrikethroughHtml` | ||
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`). | ||
`gfmStrikethrough` is a function that can be called with options and returns | ||
an extension for micromark to parse strikethrough (can be passed in | ||
`extensions`). | ||
`gfmStrikethroughHtml` is an extension for micromark to compile as `<del>` | ||
elements (can be passed in `htmlExtensions`). | ||
@@ -63,6 +94,12 @@ ##### `options` | ||
— markdown processor powered by plugins | ||
* [`remarkjs/remark-gfm`](https://github.com/remarkjs/remark-gfm) | ||
— remark plugin using this and other GFM features | ||
* [`micromark/micromark`][micromark] | ||
— the smallest commonmark-compliant markdown parser that exists | ||
* [`micromark/micromark-extension-gfm`][micromark-extension-gfm] | ||
— micromark extension combining this with other GFM features | ||
* [`syntax-tree/mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough] | ||
— mdast utility to support strikethrough | ||
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm) | ||
— mdast utility to support GFM | ||
* [`syntax-tree/mdast-util-from-markdown`][from-markdown] | ||
@@ -135,6 +172,6 @@ — mdast parser using `micromark` to create mdast from markdown | ||
[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- | ||
[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
22971
15
420
1
173
Yes
5
12
1
+ Addedmicromark-util-symbol@^1.0.0
+ Addedmicromark-util-types@^1.0.0
+ Addedmicromark-util-character@1.2.0(transitive)
+ Addedmicromark-util-chunked@1.1.0(transitive)
+ Addedmicromark-util-classify-character@1.1.0(transitive)
+ Addedmicromark-util-resolve-all@1.1.0(transitive)
+ Addedmicromark-util-symbol@1.1.0(transitive)
+ Addedmicromark-util-types@1.1.0(transitive)
- Removedmicromark@~2.11.0
- Removedcharacter-entities@1.2.4(transitive)
- Removedcharacter-entities-legacy@1.1.4(transitive)
- Removedcharacter-reference-invalid@1.1.4(transitive)
- Removeddebug@4.3.5(transitive)
- Removedis-alphabetical@1.0.4(transitive)
- Removedis-alphanumerical@1.0.4(transitive)
- Removedis-decimal@1.0.4(transitive)
- Removedis-hexadecimal@1.0.4(transitive)
- Removedmicromark@2.11.4(transitive)
- Removedms@2.1.2(transitive)
- Removedparse-entities@2.0.0(transitive)