remark-lint-no-html
Advanced tools
Comparing version
43
index.js
@@ -12,3 +12,4 @@ /** | ||
* | ||
* @example {"name": "ok.md"} | ||
* @example | ||
* {"name": "ok.md"} | ||
* | ||
@@ -19,7 +20,9 @@ * # Hello | ||
* | ||
* @example {"name": "not-ok.md", "label": "input"} | ||
* @example | ||
* {"name": "not-ok.md", "label": "input"} | ||
* | ||
* <h1>Hello</h1> | ||
* | ||
* @example {"name": "not-ok.md", "label": "output"} | ||
* @example | ||
* {"name": "not-ok.md", "label": "output"} | ||
* | ||
@@ -29,20 +32,22 @@ * 1:1-1:15: Do not use HTML in markdown | ||
'use strict' | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
*/ | ||
var rule = require('unified-lint-rule') | ||
var visit = require('unist-util-visit') | ||
var generated = require('unist-util-generated') | ||
import {lintRule} from 'unified-lint-rule' | ||
import {visit} from 'unist-util-visit' | ||
import {generated} from 'unist-util-generated' | ||
module.exports = rule('remark-lint:no-html', noHTML) | ||
const remarkLintNoHtml = lintRule( | ||
'remark-lint:no-html', | ||
/** @type {import('unified-lint-rule').Rule<Root, void>} */ | ||
(tree, file) => { | ||
visit(tree, 'html', (node) => { | ||
if (!generated(node) && !/^\s*<!--/.test(node.value)) { | ||
file.message('Do not use HTML in markdown', node) | ||
} | ||
}) | ||
} | ||
) | ||
var reason = 'Do not use HTML in markdown' | ||
function noHTML(tree, file) { | ||
visit(tree, 'html', visitor) | ||
function visitor(node) { | ||
if (!generated(node) && !/^\s*<!--/.test(node.value)) { | ||
file.message(reason, node) | ||
} | ||
} | ||
} | ||
export default remarkLintNoHtml |
{ | ||
"name": "remark-lint-no-html", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "remark-lint rule to warn when HTML nodes are used", | ||
@@ -23,11 +23,27 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"unified-lint-rule": "^1.0.0", | ||
"unist-util-generated": "^1.1.0", | ||
"unist-util-visit": "^2.0.0" | ||
"@types/mdast": "^3.0.0", | ||
"unified": "^10.0.0", | ||
"unified-lint-rule": "^2.0.0", | ||
"unist-util-generated": "^2.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
}, | ||
"xo": false | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage" | ||
}, | ||
"xo": false, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -54,2 +54,5 @@ <!--This file is generated--> | ||
This package is [ESM only][esm]: | ||
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
[npm][]: | ||
@@ -61,2 +64,5 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintNoHtml`. | ||
## Use | ||
@@ -88,10 +94,13 @@ | ||
```diff | ||
var remark = require('remark') | ||
var report = require('vfile-reporter') | ||
import {remark} from 'remark' | ||
import {reporter} from 'vfile-reporter' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintNoHtml from 'remark-lint-no-html' | ||
remark() | ||
.use(require('remark-lint')) | ||
+ .use(require('remark-lint-no-html')) | ||
.process('_Emphasis_ and **importance**', function (err, file) { | ||
console.error(report(err || file)) | ||
.use(remarkLint) | ||
+ .use(remarkLintNoHtml) | ||
.process('_Emphasis_ and **importance**') | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
@@ -114,5 +123,5 @@ ``` | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg | ||
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/remarkjs/remark-lint | ||
[build]: https://github.com/remarkjs/remark-lint/actions | ||
@@ -137,6 +146,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/remark | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -143,0 +154,0 @@ |
6114
24.7%4
33.33%62
58.97%161
7.33%Yes
NaN5
66.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated