@putout/processor-markdown 6.0.0 → 7.0.0
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 +5 -1
- package/lib/markdown.js +49 -102
- package/lib/parse-place.js +2 -4
- package/lib/parse-store.js +1 -3
- package/lib/rules/remove-trailing-whitespaces-from-heading.mjs +2 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/processor-markdown.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/processor-markdown "npm"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
> **Markdown**, the simple and easy-to-use markup language you can use to format virtually any document.
|
|
7
|
+
>
|
|
8
|
+
> (c) [markdownguide.org](https://www.markdownguide.org/)
|
|
9
|
+
|
|
10
|
+
🐊[**Putout**](https://github.com/coderaiser/putout) processor adds ability to get **JavaScript**, **JSON** and **TypeScript** code from markdown files.
|
|
7
11
|
|
|
8
12
|
## Install
|
|
9
13
|
|
package/lib/markdown.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import jsonProcessor from '@putout/processor-json';
|
|
2
|
+
import stringify from 'remark-stringify';
|
|
3
|
+
import preset from 'remark-preset-lint-consistent';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
import {run} from './rules/index.mjs';
|
|
6
|
+
import {visit} from 'unist-util-visit';
|
|
7
|
+
import {unified} from 'unified';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
import {toPlace} from './parse-place.js';
|
|
10
|
+
import {initParseStore} from './parse-store.js';
|
|
7
11
|
|
|
8
12
|
const parseStore = initParseStore();
|
|
9
13
|
|
|
@@ -18,36 +22,11 @@ const stringifyOptions = {
|
|
|
18
22
|
},
|
|
19
23
|
};
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
export const files = [
|
|
22
26
|
'*.md',
|
|
23
27
|
];
|
|
24
28
|
|
|
25
|
-
const
|
|
26
|
-
const {default: stringify} = await import('remark-stringify');
|
|
27
|
-
const {default: preset} = await import('remark-preset-lint-consistent');
|
|
28
|
-
const {default: jsonProcessor} = await import('@putout/processor-json');
|
|
29
|
-
const {run} = await import('./rules/index.mjs');
|
|
30
|
-
const {visit} = await import('unist-util-visit');
|
|
31
|
-
const {unified} = await import('unified');
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
unified,
|
|
35
|
-
stringify,
|
|
36
|
-
visit,
|
|
37
|
-
preset,
|
|
38
|
-
jsonProcessor,
|
|
39
|
-
run,
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
module.exports.find = async (rawSource) => {
|
|
44
|
-
const {
|
|
45
|
-
unified,
|
|
46
|
-
stringify,
|
|
47
|
-
preset,
|
|
48
|
-
run,
|
|
49
|
-
} = await loadDependencies();
|
|
50
|
-
|
|
29
|
+
export const find = async (rawSource) => {
|
|
51
30
|
await parseStore.init();
|
|
52
31
|
|
|
53
32
|
const {messages} = await unified()
|
|
@@ -61,14 +40,7 @@ module.exports.find = async (rawSource) => {
|
|
|
61
40
|
.map(toPlace);
|
|
62
41
|
};
|
|
63
42
|
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
unified,
|
|
67
|
-
stringify,
|
|
68
|
-
preset,
|
|
69
|
-
run,
|
|
70
|
-
} = await loadDependencies();
|
|
71
|
-
|
|
43
|
+
export const fix = async (rawSource) => {
|
|
72
44
|
await parseStore.init();
|
|
73
45
|
|
|
74
46
|
const {value} = await unified()
|
|
@@ -81,14 +53,7 @@ module.exports.fix = async (rawSource) => {
|
|
|
81
53
|
return value;
|
|
82
54
|
};
|
|
83
55
|
|
|
84
|
-
|
|
85
|
-
const {
|
|
86
|
-
unified,
|
|
87
|
-
stringify,
|
|
88
|
-
visit,
|
|
89
|
-
jsonProcessor,
|
|
90
|
-
} = await loadDependencies();
|
|
91
|
-
|
|
56
|
+
export const branch = async (rawSource) => {
|
|
92
57
|
const list = [];
|
|
93
58
|
|
|
94
59
|
await unified()
|
|
@@ -96,7 +61,6 @@ module.exports.branch = async (rawSource) => {
|
|
|
96
61
|
.use(collect, {
|
|
97
62
|
list,
|
|
98
63
|
visit,
|
|
99
|
-
jsonProcessor,
|
|
100
64
|
})
|
|
101
65
|
.use(stringify)
|
|
102
66
|
.process(rawSource);
|
|
@@ -104,14 +68,7 @@ module.exports.branch = async (rawSource) => {
|
|
|
104
68
|
return list;
|
|
105
69
|
};
|
|
106
70
|
|
|
107
|
-
|
|
108
|
-
const {
|
|
109
|
-
unified,
|
|
110
|
-
stringify,
|
|
111
|
-
visit,
|
|
112
|
-
jsonProcessor,
|
|
113
|
-
} = await loadDependencies();
|
|
114
|
-
|
|
71
|
+
export const merge = async (rawSource, list) => {
|
|
115
72
|
const newList = list.slice();
|
|
116
73
|
|
|
117
74
|
const {value} = await unified()
|
|
@@ -120,7 +77,6 @@ module.exports.merge = async (rawSource, list) => {
|
|
|
120
77
|
list: newList,
|
|
121
78
|
rawSource,
|
|
122
79
|
visit,
|
|
123
|
-
jsonProcessor,
|
|
124
80
|
})
|
|
125
81
|
.use(stringify, stringifyOptions)
|
|
126
82
|
.process(rawSource);
|
|
@@ -130,70 +86,61 @@ module.exports.merge = async (rawSource, list) => {
|
|
|
130
86
|
return value;
|
|
131
87
|
};
|
|
132
88
|
|
|
133
|
-
const collect = ({list, visit}) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
89
|
+
const collect = ({list, visit}) => (node) => {
|
|
90
|
+
visit(node, 'code', (node) => {
|
|
91
|
+
const {lang, value} = node;
|
|
92
|
+
const startLine = node.position.start.line;
|
|
93
|
+
|
|
94
|
+
if (/^(js|javascript)$/.test(lang)) {
|
|
95
|
+
list.push({
|
|
96
|
+
startLine,
|
|
97
|
+
source: value,
|
|
98
|
+
extension: 'js',
|
|
99
|
+
});
|
|
140
100
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (/^(ts|typescript)$/.test(lang)) {
|
|
105
|
+
list.push({
|
|
106
|
+
startLine,
|
|
107
|
+
source: value,
|
|
108
|
+
extension: 'ts',
|
|
109
|
+
});
|
|
150
110
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (lang === 'json') {
|
|
115
|
+
const source = jsonProcessor.toJS(value);
|
|
160
116
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
};
|
|
117
|
+
list.push({
|
|
118
|
+
startLine,
|
|
119
|
+
source,
|
|
120
|
+
extension: 'json',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
172
124
|
};
|
|
173
125
|
|
|
174
|
-
const apply = ({list, visit
|
|
126
|
+
const apply = ({list, visit}) => (node) => {
|
|
175
127
|
visit(node, 'code', (node) => {
|
|
176
128
|
const {lang} = node;
|
|
177
129
|
|
|
178
130
|
if (/^(js|javascript)$/.test(lang)) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
node.value = source;
|
|
131
|
+
node.value = list.shift();
|
|
182
132
|
return;
|
|
183
133
|
}
|
|
184
134
|
|
|
185
135
|
if (/^(ts|typescript)$/.test(lang)) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
node.value = source;
|
|
136
|
+
node.value = list.shift();
|
|
189
137
|
return;
|
|
190
138
|
}
|
|
191
139
|
|
|
192
140
|
if (lang === 'json') {
|
|
193
141
|
const code = list.shift();
|
|
194
|
-
const source = jsonProcessor.fromJS(code);
|
|
195
142
|
|
|
196
|
-
node.value =
|
|
143
|
+
node.value = jsonProcessor.fromJS(code);
|
|
197
144
|
}
|
|
198
145
|
});
|
|
199
146
|
};
|
package/lib/parse-place.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports.toPlace = function toPlace({reason, line, column, source, ruleId}) {
|
|
1
|
+
export function toPlace({reason, line, column, source, ruleId}) {
|
|
4
2
|
const {message, rule} = parseWatermark({
|
|
5
3
|
reason,
|
|
6
4
|
ruleId,
|
|
@@ -15,7 +13,7 @@ module.exports.toPlace = function toPlace({reason, line, column, source, ruleId}
|
|
|
15
13
|
column,
|
|
16
14
|
},
|
|
17
15
|
};
|
|
18
|
-
}
|
|
16
|
+
}
|
|
19
17
|
|
|
20
18
|
function parseWatermark({reason, ruleId, source}) {
|
|
21
19
|
const [watermark, remarkRule, message] = reason.split(': ');
|
package/lib/parse-store.js
CHANGED
|
@@ -6,7 +6,7 @@ const fix = (heading, tree) => {
|
|
|
6
6
|
if (latest.type === 'text' && latest.value === ' ')
|
|
7
7
|
heading.children = heading.children.slice(0, -1);
|
|
8
8
|
|
|
9
|
-
if (latest.type === 'text' &&
|
|
9
|
+
if (latest.type === 'text' && latest.value.endsWith(' '))
|
|
10
10
|
latest.value = latest.value.slice(0, -1);
|
|
11
11
|
|
|
12
12
|
tree.children[0].children = heading.children;
|
|
@@ -20,7 +20,7 @@ const traverse = (tree, {push}) => {
|
|
|
20
20
|
|
|
21
21
|
const latest = heading.children.at(-1);
|
|
22
22
|
|
|
23
|
-
if (latest.type === 'text' &&
|
|
23
|
+
if (latest.type === 'text' && latest.value.endsWith(' '))
|
|
24
24
|
push(heading);
|
|
25
25
|
};
|
|
26
26
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/processor-markdown",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "🐊Putout processor adds ability to parse markdown files and lint js snippets",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/processor-markdown#readme",
|
|
8
8
|
"main": "lib/markdown.js",
|
|
9
9
|
"release": false,
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"markdown"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@putout/test": "^
|
|
42
|
+
"@putout/test": "^5.0.0",
|
|
43
43
|
"c8": "^7.5.0",
|
|
44
44
|
"eslint": "^8.0.1",
|
|
45
45
|
"eslint-plugin-node": "^11.0.0",
|
|
46
|
-
"eslint-plugin-putout": "^
|
|
46
|
+
"eslint-plugin-putout": "^15.0.0",
|
|
47
47
|
"lerna": "^4.0.0",
|
|
48
|
-
"madrun": "^
|
|
48
|
+
"madrun": "^9.0.0",
|
|
49
49
|
"nodemon": "^2.0.1",
|
|
50
50
|
"putout": "*",
|
|
51
51
|
"supertape": "^7.0.0"
|