@putout/processor-markdown 13.1.1 → 14.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,4 +1,12 @@
1
- import {toJS, fromJS} from '@putout/operator-json';
1
+ import {
2
+ toJS,
3
+ fromJS,
4
+ __markdown,
5
+ } from '@putout/operator-json';
6
+ import {
7
+ convertJsToMarkdown,
8
+ convertMarkdownToJs,
9
+ } from 'happy-mark';
2
10
  import stringify from 'remark-stringify';
3
11
  import preset from 'remark-preset-lint-consistent';
4
12
  import remarkFrontmatter from 'remark-frontmatter';
@@ -59,8 +67,13 @@ export const fix = async (rawSource, options = {}) => {
59
67
 
60
68
  return value;
61
69
  };
70
+
62
71
  export const branch = async (rawSource) => {
63
- const list = [];
72
+ const list = [{
73
+ startLine: 0,
74
+ source: toJS(convertMarkdownToJs(rawSource), __markdown),
75
+ extension: 'md',
76
+ }];
64
77
 
65
78
  await unified()
66
79
  .use(remarkParse)
@@ -74,7 +87,9 @@ export const branch = async (rawSource) => {
74
87
  return list;
75
88
  };
76
89
  export const merge = async (rawSource, list) => {
77
- const newList = list.slice();
90
+ const [mdJs, ...newList] = list;
91
+
92
+ const md = convertJsToMarkdown(fromJS(mdJs, __markdown));
78
93
 
79
94
  const {value} = await unified()
80
95
  .use(remarkParse)
@@ -84,7 +99,7 @@ export const merge = async (rawSource, list) => {
84
99
  visit,
85
100
  })
86
101
  .use(stringify, stringifyOptions)
87
- .process(rawSource);
102
+ .process(md);
88
103
 
89
104
  return value;
90
105
  };
package/lib/plugins.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import * as removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge/index.js';
2
2
  import * as removeTrailingWhitespacesFromHeading from './rules/remove-trailing-whitespaces-from-heading/index.js';
3
- import * as mergeHeadingSpceces from './rules/merge-heading-spaces/index.js';
4
3
  import * as splitLinkWithTitle from './rules/split-link-with-title/index.js';
5
4
 
6
5
  export const plugins = [
7
6
  removeDependenciesStatusBadge,
8
7
  removeTrailingWhitespacesFromHeading,
9
- mergeHeadingSpceces,
10
8
  splitLinkWithTitle,
11
9
  ];
@@ -22,7 +22,7 @@ export const traverse = (tree, {push}) => {
22
22
  push,
23
23
  });
24
24
 
25
- if (!/link|definition/.test(type))
25
+ if (!/^(link|definition)$/.test(type))
26
26
  continue;
27
27
 
28
28
  if (title || !url.includes('"'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/processor-markdown",
3
- "version": "13.1.1",
3
+ "version": "14.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",
@@ -29,6 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@putout/operator-json": "^3.0.0",
32
+ "happy-mark": "^1.0.2",
32
33
  "once": "^1.4.0",
33
34
  "remark-frontmatter": "^5.0.0",
34
35
  "remark-parse": "^11.0.0",
@@ -45,16 +46,15 @@
45
46
  ],
46
47
  "devDependencies": {
47
48
  "@putout/test": "^15.0.0",
48
- "c8": "^10.0.0",
49
- "eslint": "^10.0.0-alpha.0",
50
- "eslint-plugin-n": "^17.0.0",
51
- "eslint-plugin-putout": "^30.0.0",
52
- "madcut": "^2.0.0",
53
- "madrun": "^12.0.0",
54
- "montag": "^1.2.1",
49
+ "eslint": "^10.0.0",
50
+ "eslint-plugin-putout": "^31.0.0",
51
+ "madcut": "^3.0.0",
52
+ "madrun": "^13.0.0",
53
+ "montag": "^2.0.0",
55
54
  "nodemon": "^3.0.1",
56
55
  "putout": "*",
57
- "supertape": "^12.0.0"
56
+ "superc8": "^12.0.0",
57
+ "supertape": "^13.0.0"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22"
@@ -1,43 +0,0 @@
1
- export const name = 'merge-heading-spaces';
2
- export const report = () => 'Merge heading spaces';
3
-
4
- export const fix = (heading) => {
5
- const newChildren = [];
6
-
7
- for (const [i, node] of heading.children.entries()) {
8
- const nextNode = heading.children[i + 1];
9
-
10
- if (bothSpaces(node, nextNode))
11
- continue;
12
-
13
- newChildren.push(node);
14
- }
15
-
16
- heading.children = newChildren;
17
- };
18
-
19
- export const traverse = (tree, {push}) => {
20
- const [heading] = tree.children;
21
-
22
- if (heading.type !== 'heading')
23
- return;
24
-
25
- for (const [i, node] of heading.children.entries()) {
26
- const nextNode = heading.children[i + 1];
27
-
28
- if (bothSpaces(node, nextNode)) {
29
- push(heading);
30
- break;
31
- }
32
- }
33
- };
34
-
35
- const bothSpaces = (node, nextNode) => {
36
- if (!nextNode)
37
- return false;
38
-
39
- if (node.type !== 'text' || node.value !== ' ')
40
- return false;
41
-
42
- return nextNode.type === 'text' && nextNode.value === ' ';
43
- };