@putout/processor-markdown 12.1.0 → 13.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/lib/markdown.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import {toJS, fromJS} from '@putout/operator-json';
2
2
  import stringify from 'remark-stringify';
3
3
  import preset from 'remark-preset-lint-consistent';
4
+ import remarkFrontmatter from 'remark-frontmatter';
5
+ import {visit} from 'unist-util-visit';
6
+ import {unified} from 'unified';
7
+ import remarkParse from 'remark-parse';
4
8
  import removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge.js';
5
9
  import removeTrailingWhitespacesFromHeading from './rules/remove-trailing-whitespaces-from-heading.js';
6
10
  import mergeHeadingSpceces from './rules/merge-heading-spaces.js';
7
11
  import {run} from './rules/index.js';
8
- import {visit} from 'unist-util-visit';
9
- import {unified} from 'unified';
10
12
  import {toPlace} from './parse-place.js';
11
- import {initParseStore} from './parse-store.js';
12
13
 
13
14
  const plugins = [
14
15
  removeDependenciesStatusBadge,
@@ -16,8 +17,6 @@ const plugins = [
16
17
  mergeHeadingSpceces,
17
18
  ];
18
19
 
19
- const parseStore = initParseStore();
20
-
21
20
  const text = ({value}) => value;
22
21
 
23
22
  const stringifyOptions = {
@@ -32,13 +31,11 @@ const stringifyOptions = {
32
31
 
33
32
  export const files = ['*.md'];
34
33
  export const find = async (rawSource, options = {}) => {
35
- await parseStore.init();
36
-
37
34
  if (!rawSource.length)
38
35
  return [];
39
36
 
40
37
  const {messages} = await unified()
41
- .use(parseStore)
38
+ .use(remarkParse)
42
39
  .use(preset)
43
40
  .use(run, {
44
41
  fix: false,
@@ -48,16 +45,17 @@ export const find = async (rawSource, options = {}) => {
48
45
  ],
49
46
  })
50
47
  .use(stringify, stringifyOptions)
48
+ .use(remarkFrontmatter, ['yaml', 'toml'])
51
49
  .process(rawSource);
52
50
 
53
51
  return messages.map(toPlace);
54
52
  };
55
53
  export const fix = async (rawSource, options = {}) => {
56
- await parseStore.init();
57
-
58
54
  const {value} = await unified()
59
- .use(parseStore)
55
+ .use(remarkParse)
60
56
  .use(preset)
57
+ .use(stringify, stringifyOptions)
58
+ .use(remarkFrontmatter, ['yaml', 'toml'])
61
59
  .use(run, {
62
60
  fix: true,
63
61
  plugins: [
@@ -65,7 +63,6 @@ export const fix = async (rawSource, options = {}) => {
65
63
  ...options.plugins || [],
66
64
  ],
67
65
  })
68
- .use(stringify, stringifyOptions)
69
66
  .process(rawSource);
70
67
 
71
68
  return value;
@@ -74,7 +71,7 @@ export const branch = async (rawSource) => {
74
71
  const list = [];
75
72
 
76
73
  await unified()
77
- .use(parseStore)
74
+ .use(remarkParse)
78
75
  .use(collect, {
79
76
  list,
80
77
  visit,
@@ -88,7 +85,7 @@ export const merge = async (rawSource, list) => {
88
85
  const newList = list.slice();
89
86
 
90
87
  const {value} = await unified()
91
- .use(parseStore)
88
+ .use(remarkParse)
92
89
  .use(apply, {
93
90
  list: newList,
94
91
  rawSource,
@@ -97,15 +94,12 @@ export const merge = async (rawSource, list) => {
97
94
  .use(stringify, stringifyOptions)
98
95
  .process(rawSource);
99
96
 
100
- await parseStore.clear();
101
-
102
97
  return value;
103
98
  };
104
99
 
105
100
  const collect = ({list, visit}) => (node) => {
106
101
  visit(node, 'code', (node) => {
107
102
  const {lang, value} = node;
108
-
109
103
  const startLine = node.position.start.line;
110
104
 
111
105
  if (/^(js|javascript)$/.test(lang)) {
@@ -38,7 +38,7 @@ const bothSpaces = (node, nextNode) => {
38
38
  if (node.type !== 'text' || node.value !== ' ')
39
39
  return false;
40
40
 
41
- return !(nextNode.type !== 'text' || nextNode.value !== ' ');
41
+ return nextNode.type === 'text' && nextNode.value === ' ';
42
42
  };
43
43
 
44
44
  export default {
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@putout/processor-markdown",
3
- "version": "12.1.0",
3
+ "version": "13.0.0",
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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/processor-markdown#readme",
8
8
  "main": "./lib/markdown.js",
9
9
  "exports": {
10
- ".": "./lib/markdown.js",
11
- "./parse-store": "./lib/parse-store.js"
10
+ ".": "./lib/markdown.js"
12
11
  },
13
12
  "release": false,
14
13
  "tag": false,
15
14
  "changelog": false,
16
15
  "repository": {
17
16
  "type": "git",
18
- "url": "git://github.com/coderaiser/putout.git"
17
+ "url": "git+https://github.com/coderaiser/putout.git"
19
18
  },
20
19
  "scripts": {
21
20
  "test": "madrun test",
@@ -29,8 +28,9 @@
29
28
  "report": "madrun report"
30
29
  },
31
30
  "dependencies": {
32
- "@putout/operator-json": "^2.0.0",
31
+ "@putout/operator-json": "^3.0.0",
33
32
  "once": "^1.4.0",
33
+ "remark-frontmatter": "^5.0.0",
34
34
  "remark-parse": "^11.0.0",
35
35
  "remark-preset-lint-consistent": "^6.0.0",
36
36
  "remark-stringify": "^11.0.0",
@@ -44,21 +44,20 @@
44
44
  "markdown"
45
45
  ],
46
46
  "devDependencies": {
47
- "@putout/test": "^9.0.0",
48
- "c8": "^9.0.0",
49
- "eslint": "^9.0.0",
47
+ "@putout/test": "^15.0.0",
48
+ "c8": "^10.0.0",
49
+ "eslint": "^10.0.0-alpha.0",
50
50
  "eslint-plugin-n": "^17.0.0",
51
- "eslint-plugin-putout": "^22.0.0",
52
- "lerna": "^6.0.1",
51
+ "eslint-plugin-putout": "^29.0.0",
53
52
  "madcut": "^2.0.0",
54
- "madrun": "^10.0.0",
53
+ "madrun": "^12.0.0",
55
54
  "montag": "^1.2.1",
56
55
  "nodemon": "^3.0.1",
57
56
  "putout": "*",
58
- "supertape": "^10.0.0"
57
+ "supertape": "^12.0.0"
59
58
  },
60
59
  "engines": {
61
- "node": ">=18"
60
+ "node": ">=22"
62
61
  },
63
62
  "publishConfig": {
64
63
  "access": "public"
@@ -1,29 +0,0 @@
1
- export const initParseStore = () => {
2
- let cache = null;
3
- let parse = null;
4
-
5
- const fn = function needContext(a) {
6
- parse.call(this, a);
7
- const {parser} = this;
8
-
9
- this.parser = function(...a) {
10
- if (cache)
11
- return cache;
12
-
13
- cache = parser(...a);
14
-
15
- return cache;
16
- };
17
- };
18
-
19
- fn.init = async () => {
20
- cache = null;
21
- ({default: parse} = await import('remark-parse'));
22
- };
23
-
24
- fn.clear = async () => {
25
- cache = null;
26
- };
27
-
28
- return fn;
29
- };