@putout/processor-markdown 14.0.3 → 14.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -25,8 +25,7 @@ npm i @putout/processor-markdown -D
|
|
|
25
25
|
|
|
26
26
|
## Rules
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
- [Split link with title](https://github.com/coderaiser/putout/tree/master/packages/processor-markdown/lib/rules/split-link-with-title/README.md);
|
|
28
|
+
Checkout `markdown`-related rules in [`@putout/plugin-markdown`](https://github.com/coderaiser/putout/tree/master/packages/plugin-markdown)
|
|
30
29
|
|
|
31
30
|
## License
|
|
32
31
|
|
package/lib/markdown.js
CHANGED
|
@@ -15,7 +15,6 @@ import {unified} from 'unified';
|
|
|
15
15
|
import remarkParse from 'remark-parse';
|
|
16
16
|
import {run} from './rules/index.js';
|
|
17
17
|
import {toPlace} from './parse-place.js';
|
|
18
|
-
import {plugins} from './plugins.js';
|
|
19
18
|
|
|
20
19
|
const text = ({value}) => value;
|
|
21
20
|
|
|
@@ -31,6 +30,8 @@ const stringifyOptions = {
|
|
|
31
30
|
|
|
32
31
|
export const files = ['*.md'];
|
|
33
32
|
export const find = async (rawSource, options = {}) => {
|
|
33
|
+
const {plugins = []} = options;
|
|
34
|
+
|
|
34
35
|
if (!rawSource.length)
|
|
35
36
|
return [];
|
|
36
37
|
|
|
@@ -39,10 +40,7 @@ export const find = async (rawSource, options = {}) => {
|
|
|
39
40
|
.use(preset)
|
|
40
41
|
.use(run, {
|
|
41
42
|
fix: false,
|
|
42
|
-
plugins
|
|
43
|
-
...plugins,
|
|
44
|
-
...options.plugins || [],
|
|
45
|
-
],
|
|
43
|
+
plugins,
|
|
46
44
|
})
|
|
47
45
|
.use(stringify, stringifyOptions)
|
|
48
46
|
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
@@ -51,6 +49,7 @@ export const find = async (rawSource, options = {}) => {
|
|
|
51
49
|
return messages.map(toPlace);
|
|
52
50
|
};
|
|
53
51
|
export const fix = async (rawSource, options = {}) => {
|
|
52
|
+
const {plugins = []} = options;
|
|
54
53
|
const {value} = await unified()
|
|
55
54
|
.use(remarkParse)
|
|
56
55
|
.use(preset)
|
|
@@ -58,10 +57,7 @@ export const fix = async (rawSource, options = {}) => {
|
|
|
58
57
|
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
59
58
|
.use(run, {
|
|
60
59
|
fix: true,
|
|
61
|
-
plugins
|
|
62
|
-
...plugins,
|
|
63
|
-
...options.plugins || [],
|
|
64
|
-
],
|
|
60
|
+
plugins,
|
|
65
61
|
})
|
|
66
62
|
.process(rawSource);
|
|
67
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/processor-markdown",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout processor adds ability to parse markdown files and lint JavaScript, JSX, TypeScript and JSON snippets",
|
package/lib/plugins.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export const name = 'remove-trailing-whitespaces-from-heading';
|
|
2
|
-
export const report = () => 'Avoid trailing whitespaces';
|
|
3
|
-
|
|
4
|
-
export const fix = (heading, tree) => {
|
|
5
|
-
const latest = heading.children.at(-1);
|
|
6
|
-
|
|
7
|
-
if (latest.type === 'text' && latest.value === ' ')
|
|
8
|
-
heading.children = heading.children.slice(0, -1);
|
|
9
|
-
|
|
10
|
-
if (latest.type === 'text' && latest.value.endsWith(' '))
|
|
11
|
-
latest.value = latest.value.slice(0, -1);
|
|
12
|
-
|
|
13
|
-
tree.children[0].children = heading.children;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const traverse = (tree, {push}) => {
|
|
17
|
-
const [heading] = tree.children;
|
|
18
|
-
|
|
19
|
-
if (heading.type !== 'heading')
|
|
20
|
-
return;
|
|
21
|
-
|
|
22
|
-
const latest = heading.children.at(-1);
|
|
23
|
-
|
|
24
|
-
if (latest.type === 'text' && latest.value.endsWith(' '))
|
|
25
|
-
push(heading);
|
|
26
|
-
};
|