-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
remark-lint-strikethrough-marker
Closes GH-259. Closes GH-260. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
- Loading branch information
Showing
5 changed files
with
368 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* @author Denis Augsburger | ||
* @copyright 2021 Denis Augsburger | ||
* @license MIT | ||
* @module strikethrough-marker | ||
* @fileoverview | ||
* Warn for violating strikethrough markers. | ||
* | ||
* Options: `'consistent'`, `'~'`, or `'~~'`, default: `'consistent'`. | ||
* | ||
* `'consistent'` detects the first used strikethrough style and warns when | ||
* subsequent strikethrough use different styles. | ||
* | ||
* ## Fix | ||
* | ||
* See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
* on how to automatically fix warnings for this rule. | ||
* | ||
* @example {"setting": "~", "name": "ok.md", "gfm": true} | ||
* | ||
* ~foo~ | ||
* | ||
* @example {"setting": "~", "name": "not-ok.md", "label": "input", "gfm": true} | ||
* | ||
* ~~foo~~ | ||
* | ||
* @example {"setting": "~", "name": "not-ok.md", "label": "output", "gfm": true} | ||
* | ||
* 1:1-1:8: Strikethrough should use `~` as a marker | ||
* | ||
* @example {"setting": "~~", "name": "ok.md", "gfm": true} | ||
* | ||
* ~~foo~~ | ||
* | ||
* @example {"setting": "~~", "name": "not-ok.md", "label": "input", "gfm": true} | ||
* | ||
* ~foo~ | ||
* | ||
* @example {"setting": "~~", "name": "not-ok.md", "label": "output", "gfm": true} | ||
* | ||
* 1:1-1:6: Strikethrough should use `~~` as a marker | ||
* | ||
* @example {"name": "not-ok.md", "label": "input", "gfm": true} | ||
* | ||
* ~~foo~~ | ||
* ~bar~ | ||
* | ||
* @example {"name": "not-ok.md", "label": "output", "gfm": true} | ||
* | ||
* 2:1-2:6: Strikethrough should use `~~` as a marker | ||
* | ||
* @example {"setting": "💩", "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true} | ||
* | ||
* 1:1: Incorrect strikethrough marker `💩`: use either `'consistent'`, `'~'`, or `'~~'` | ||
*/ | ||
|
||
'use strict' | ||
|
||
var rule = require('unified-lint-rule') | ||
var visit = require('unist-util-visit') | ||
var position = require('unist-util-position') | ||
var generated = require('unist-util-generated') | ||
|
||
module.exports = rule('remark-lint:strikethrough-marker', strikethroughMarker) | ||
|
||
var markers = {null: true, '~': true, '~~': true} | ||
|
||
function strikethroughMarker(tree, file, option) { | ||
var contents = String(file) | ||
var preferred = | ||
typeof option === 'string' && option !== 'consistent' ? option : null | ||
|
||
if (markers[preferred] !== true) { | ||
file.fail( | ||
'Incorrect strikethrough marker `' + | ||
preferred + | ||
"`: use either `'consistent'`, `'~'`, or `'~~'`" | ||
) | ||
} | ||
|
||
visit(tree, 'delete', visitor) | ||
|
||
function visitor(node) { | ||
var marker | ||
|
||
if (!generated(node)) { | ||
var offset = position.start(node).offset | ||
marker = | ||
contents.slice(offset, offset + 2) === '~~' | ||
? contents.slice(offset, offset + 2) | ||
: contents.slice(offset, offset + 1) | ||
|
||
if (preferred) { | ||
if (marker !== preferred) { | ||
file.message( | ||
'Strikethrough should use `' + preferred + '` as a marker', | ||
node | ||
) | ||
} | ||
} else { | ||
preferred = marker | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "remark-lint-strikethrough-marker", | ||
"version": "2.0.1", | ||
"description": "remark-lint rule to warn when strikethrough markers violate the given style", | ||
"license": "MIT", | ||
"keywords": [ | ||
"remark", | ||
"lint", | ||
"rule", | ||
"remark-lint-rule", | ||
"strikethrough", | ||
"marker" | ||
], | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strikethrough-marker", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Denis Augsburger <denis.augsburger@simpleen.io> (https://simpleen.io)", | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"unified-lint-rule": "^1.0.0", | ||
"unist-util-generated": "^1.1.0", | ||
"unist-util-position": "^3.0.0", | ||
"unist-util-visit": "^2.0.0" | ||
}, | ||
"xo": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
<!--This file is generated--> | ||
|
||
# remark-lint-strikethrough-marker | ||
|
||
[![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] | ||
|
||
Warn for violating strikethrough markers. | ||
|
||
Options: `'consistent'`, `'~'`, or `'~~'`, default: `'consistent'`. | ||
|
||
`'consistent'` detects the first used strikethrough style and warns when | ||
subsequent strikethrough use different styles. | ||
|
||
## Fix | ||
|
||
See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
on how to automatically fix warnings for this rule. | ||
|
||
## Presets | ||
|
||
This rule is not included in any default preset | ||
|
||
## Example | ||
|
||
##### `ok.md` | ||
|
||
When configured with `'~'`. | ||
|
||
###### In | ||
|
||
Note: this example uses [GFM][]. | ||
|
||
```markdown | ||
~foo~ | ||
``` | ||
|
||
###### Out | ||
|
||
No messages. | ||
|
||
##### `not-ok.md` | ||
|
||
When configured with `'~'`. | ||
|
||
###### In | ||
|
||
Note: this example uses [GFM][]. | ||
|
||
```markdown | ||
~~foo~~ | ||
``` | ||
|
||
###### Out | ||
|
||
```text | ||
1:1-1:8: Strikethrough should use `~` as a marker | ||
``` | ||
|
||
##### `ok.md` | ||
|
||
When configured with `'~~'`. | ||
|
||
###### In | ||
|
||
Note: this example uses [GFM][]. | ||
|
||
```markdown | ||
~~foo~~ | ||
``` | ||
|
||
###### Out | ||
|
||
No messages. | ||
|
||
##### `not-ok.md` | ||
|
||
When configured with `'~~'`. | ||
|
||
###### In | ||
|
||
Note: this example uses [GFM][]. | ||
|
||
```markdown | ||
~foo~ | ||
``` | ||
|
||
###### Out | ||
|
||
```text | ||
1:1-1:6: Strikethrough should use `~~` as a marker | ||
``` | ||
|
||
##### `not-ok.md` | ||
|
||
###### In | ||
|
||
Note: this example uses [GFM][]. | ||
|
||
```markdown | ||
~~foo~~ | ||
~bar~ | ||
``` | ||
|
||
###### Out | ||
|
||
```text | ||
2:1-2:6: Strikethrough should use `~~` as a marker | ||
``` | ||
|
||
##### `not-ok.md` | ||
|
||
When configured with `'💩'`. | ||
|
||
###### Out | ||
|
||
```text | ||
1:1: Incorrect strikethrough marker `💩`: use either `'consistent'`, `'~'`, or `'~~'` | ||
``` | ||
|
||
## Install | ||
|
||
[npm][]: | ||
|
||
```sh | ||
npm install remark-lint-strikethrough-marker | ||
``` | ||
|
||
## Use | ||
|
||
You probably want to use it on the CLI through a config file: | ||
|
||
```diff | ||
… | ||
"remarkConfig": { | ||
"plugins": [ | ||
… | ||
"lint", | ||
+ "lint-strikethrough-marker", | ||
… | ||
] | ||
} | ||
… | ||
``` | ||
|
||
Or use it on the CLI directly | ||
|
||
```sh | ||
remark -u lint -u lint-strikethrough-marker readme.md | ||
``` | ||
|
||
Or use this on the API: | ||
|
||
```diff | ||
var remark = require('remark') | ||
var report = require('vfile-reporter') | ||
|
||
remark() | ||
.use(require('remark-lint')) | ||
+ .use(require('remark-lint-strikethrough-marker')) | ||
.process('_Emphasis_ and **importance**', function (err, file) { | ||
console.error(report(err || file)) | ||
}) | ||
``` | ||
|
||
## Contribute | ||
|
||
See [`contributing.md`][contributing] in [`remarkjs/.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, organization, or community you agree to | ||
abide by its terms. | ||
|
||
## License | ||
|
||
[MIT][license] © [Titus Wormer][author] | ||
|
||
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
|
||
[build]: https://github.com/remarkjs/remark-lint/actions | ||
|
||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
|
||
[coverage]: https://codecov.io/github/remarkjs/remark-lint | ||
|
||
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-strikethrough-marker.svg | ||
|
||
[downloads]: https://www.npmjs.com/package/remark-lint-strikethrough-marker | ||
|
||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-strikethrough-marker.svg | ||
|
||
[size]: https://bundlephobia.com/result?p=remark-lint-strikethrough-marker | ||
|
||
[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/remarkjs/remark/discussions | ||
|
||
[npm]: https://docs.npmjs.com/cli/install | ||
|
||
[health]: https://github.com/remarkjs/.github | ||
|
||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
|
||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
|
||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
|
||
[license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
|
||
[author]: https://wooorm.com | ||
|
||
[gfm]: https://github.com/remarkjs/remark-gfm |