@putout/processor-markdown 12.0.0 → 12.2.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,17 +1,15 @@
1
- import {
2
- toJS,
3
- fromJS,
4
- } from '@putout/operator-json';
1
+ import {toJS, fromJS} from '@putout/operator-json';
5
2
  import stringify from 'remark-stringify';
6
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';
7
8
  import removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge.js';
8
9
  import removeTrailingWhitespacesFromHeading from './rules/remove-trailing-whitespaces-from-heading.js';
9
10
  import mergeHeadingSpceces from './rules/merge-heading-spaces.js';
10
11
  import {run} from './rules/index.js';
11
- import {visit} from 'unist-util-visit';
12
- import {unified} from 'unified';
13
12
  import {toPlace} from './parse-place.js';
14
- import {initParseStore} from './parse-store.js';
15
13
 
16
14
  const plugins = [
17
15
  removeDependenciesStatusBadge,
@@ -19,8 +17,6 @@ const plugins = [
19
17
  mergeHeadingSpceces,
20
18
  ];
21
19
 
22
- const parseStore = initParseStore();
23
-
24
20
  const text = ({value}) => value;
25
21
 
26
22
  const stringifyOptions = {
@@ -35,13 +31,11 @@ const stringifyOptions = {
35
31
 
36
32
  export const files = ['*.md'];
37
33
  export const find = async (rawSource, options = {}) => {
38
- await parseStore.init();
39
-
40
34
  if (!rawSource.length)
41
35
  return [];
42
36
 
43
37
  const {messages} = await unified()
44
- .use(parseStore)
38
+ .use(remarkParse)
45
39
  .use(preset)
46
40
  .use(run, {
47
41
  fix: false,
@@ -51,16 +45,17 @@ export const find = async (rawSource, options = {}) => {
51
45
  ],
52
46
  })
53
47
  .use(stringify, stringifyOptions)
48
+ .use(remarkFrontmatter, ['yaml', 'toml'])
54
49
  .process(rawSource);
55
50
 
56
51
  return messages.map(toPlace);
57
52
  };
58
53
  export const fix = async (rawSource, options = {}) => {
59
- await parseStore.init();
60
-
61
54
  const {value} = await unified()
62
- .use(parseStore)
55
+ .use(remarkParse)
63
56
  .use(preset)
57
+ .use(stringify, stringifyOptions)
58
+ .use(remarkFrontmatter, ['yaml', 'toml'])
64
59
  .use(run, {
65
60
  fix: true,
66
61
  plugins: [
@@ -68,7 +63,6 @@ export const fix = async (rawSource, options = {}) => {
68
63
  ...options.plugins || [],
69
64
  ],
70
65
  })
71
- .use(stringify, stringifyOptions)
72
66
  .process(rawSource);
73
67
 
74
68
  return value;
@@ -77,7 +71,7 @@ export const branch = async (rawSource) => {
77
71
  const list = [];
78
72
 
79
73
  await unified()
80
- .use(parseStore)
74
+ .use(remarkParse)
81
75
  .use(collect, {
82
76
  list,
83
77
  visit,
@@ -91,7 +85,7 @@ export const merge = async (rawSource, list) => {
91
85
  const newList = list.slice();
92
86
 
93
87
  const {value} = await unified()
94
- .use(parseStore)
88
+ .use(remarkParse)
95
89
  .use(apply, {
96
90
  list: newList,
97
91
  rawSource,
@@ -100,15 +94,12 @@ export const merge = async (rawSource, list) => {
100
94
  .use(stringify, stringifyOptions)
101
95
  .process(rawSource);
102
96
 
103
- await parseStore.clear();
104
-
105
97
  return value;
106
98
  };
107
99
 
108
100
  const collect = ({list, visit}) => (node) => {
109
101
  visit(node, 'code', (node) => {
110
102
  const {lang, value} = node;
111
-
112
103
  const startLine = node.position.start.line;
113
104
 
114
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.0.0",
3
+ "version": "12.2.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",
@@ -31,11 +30,12 @@
31
30
  "dependencies": {
32
31
  "@putout/operator-json": "^2.0.0",
33
32
  "once": "^1.4.0",
33
+ "remark-frontmatter": "^5.0.0",
34
34
  "remark-parse": "^11.0.0",
35
- "remark-preset-lint-consistent": "^5.0.0",
35
+ "remark-preset-lint-consistent": "^6.0.0",
36
36
  "remark-stringify": "^11.0.0",
37
37
  "unified": "^11.0.3",
38
- "unified-lint-rule": "^2.1.0",
38
+ "unified-lint-rule": "^3.0.0",
39
39
  "unist-util-visit": "^5.0.0"
40
40
  },
41
41
  "keywords": [
@@ -44,18 +44,18 @@
44
44
  "markdown"
45
45
  ],
46
46
  "devDependencies": {
47
- "@putout/test": "^8.0.0",
48
- "c8": "^9.0.0",
49
- "eslint": "^9.0.0-alpha.0",
50
- "eslint-plugin-n": "^17.0.0-0",
51
- "eslint-plugin-putout": "^22.0.0",
47
+ "@putout/test": "^11.0.0",
48
+ "c8": "^10.0.0",
49
+ "eslint": "^9.0.0",
50
+ "eslint-plugin-n": "^17.0.0",
51
+ "eslint-plugin-putout": "^24.0.0",
52
52
  "lerna": "^6.0.1",
53
- "madcut": "^1.0.0",
53
+ "madcut": "^2.0.0",
54
54
  "madrun": "^10.0.0",
55
55
  "montag": "^1.2.1",
56
56
  "nodemon": "^3.0.1",
57
57
  "putout": "*",
58
- "supertape": "^9.0.0"
58
+ "supertape": "^10.0.0"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=18"
@@ -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
- };