@putout/processor-markdown 13.0.0 → 13.1.1

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,7 +25,8 @@ npm i @putout/processor-markdown -D
25
25
 
26
26
  ## Rules
27
27
 
28
- - [Remove dependencies status badges](https://github.com/coderaiser/putout/tree/master/packages/processor-markdown/lib/rules/remove-dependencies-status-badge.md)
28
+ - [Remove dependencies status badges](https://github.com/coderaiser/putout/tree/master/packages/processor-markdown/lib/rules/remove-dependencies-status-badge/README.md)
29
+ - [Split link with title](https://github.com/coderaiser/putout/tree/master/packages/processor-markdown/lib/rules/split-link-with-title/README.md);
29
30
 
30
31
  ## License
31
32
 
package/lib/markdown.js CHANGED
@@ -5,17 +5,9 @@ import remarkFrontmatter from 'remark-frontmatter';
5
5
  import {visit} from 'unist-util-visit';
6
6
  import {unified} from 'unified';
7
7
  import remarkParse from 'remark-parse';
8
- import removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge.js';
9
- import removeTrailingWhitespacesFromHeading from './rules/remove-trailing-whitespaces-from-heading.js';
10
- import mergeHeadingSpceces from './rules/merge-heading-spaces.js';
11
8
  import {run} from './rules/index.js';
12
9
  import {toPlace} from './parse-place.js';
13
-
14
- const plugins = [
15
- removeDependenciesStatusBadge,
16
- removeTrailingWhitespacesFromHeading,
17
- mergeHeadingSpceces,
18
- ];
10
+ import {plugins} from './plugins.js';
19
11
 
20
12
  const text = ({value}) => value;
21
13
 
package/lib/plugins.js ADDED
@@ -0,0 +1,11 @@
1
+ import * as removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge/index.js';
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
+ import * as splitLinkWithTitle from './rules/split-link-with-title/index.js';
5
+
6
+ export const plugins = [
7
+ removeDependenciesStatusBadge,
8
+ removeTrailingWhitespacesFromHeading,
9
+ mergeHeadingSpceces,
10
+ splitLinkWithTitle,
11
+ ];
@@ -1,6 +1,7 @@
1
- const report = () => 'Merge heading spaces';
1
+ export const name = 'merge-heading-spaces';
2
+ export const report = () => 'Merge heading spaces';
2
3
 
3
- const fix = (heading) => {
4
+ export const fix = (heading) => {
4
5
  const newChildren = [];
5
6
 
6
7
  for (const [i, node] of heading.children.entries()) {
@@ -15,7 +16,7 @@ const fix = (heading) => {
15
16
  heading.children = newChildren;
16
17
  };
17
18
 
18
- const traverse = (tree, {push}) => {
19
+ export const traverse = (tree, {push}) => {
19
20
  const [heading] = tree.children;
20
21
 
21
22
  if (heading.type !== 'heading')
@@ -40,10 +41,3 @@ const bothSpaces = (node, nextNode) => {
40
41
 
41
42
  return nextNode.type === 'text' && nextNode.value === ' ';
42
43
  };
43
-
44
- export default {
45
- name: 'merge-heading-spaces',
46
- fix,
47
- traverse,
48
- report,
49
- };
@@ -1,15 +1,10 @@
1
- const report = () => 'Remove dependencies status badge';
1
+ export const name = 'remove-dependencies-status-badge';
2
2
 
3
- const noop = () => {};
3
+ export const report = () => 'Remove dependencies status badge';
4
4
 
5
- export default {
6
- name: 'remove-dependencies-status-badge',
7
- traverse,
8
- fix,
9
- report,
10
- };
5
+ const noop = () => {};
11
6
 
12
- function fix(node, tree) {
7
+ export const fix = (node, tree) => {
13
8
  const children = tree.children.filter(isDependencyStatus());
14
9
 
15
10
  tree.children = children;
@@ -22,11 +17,11 @@ function fix(node, tree) {
22
17
  const headingChildren = heading.children.filter(isDependencyLink);
23
18
 
24
19
  tree.children[0].children = headingChildren;
25
- }
20
+ };
26
21
 
27
- function traverse(tree, {push}) {
22
+ export const traverse = (tree, {push}) => {
28
23
  tree.children.filter(isDependencyStatus(push));
29
- }
24
+ };
30
25
 
31
26
  const isDependencyStatus = (push = noop) => (child) => {
32
27
  if (child.type !== 'definition')
@@ -1,6 +1,7 @@
1
- const report = () => 'Avoid trailing whitespaces';
1
+ export const name = 'remove-trailing-whitespaces-from-heading';
2
+ export const report = () => 'Avoid trailing whitespaces';
2
3
 
3
- const fix = (heading, tree) => {
4
+ export const fix = (heading, tree) => {
4
5
  const latest = heading.children.at(-1);
5
6
 
6
7
  if (latest.type === 'text' && latest.value === ' ')
@@ -12,7 +13,7 @@ const fix = (heading, tree) => {
12
13
  tree.children[0].children = heading.children;
13
14
  };
14
15
 
15
- const traverse = (tree, {push}) => {
16
+ export const traverse = (tree, {push}) => {
16
17
  const [heading] = tree.children;
17
18
 
18
19
  if (heading.type !== 'heading')
@@ -23,10 +24,3 @@ const traverse = (tree, {push}) => {
23
24
  if (latest.type === 'text' && latest.value.endsWith(' '))
24
25
  push(heading);
25
26
  };
26
-
27
- export default {
28
- name: 'remove-trailing-whitespaces-from-heading',
29
- fix,
30
- traverse,
31
- report,
32
- };
@@ -0,0 +1,14 @@
1
+ # Split link with title (split-link-with-title)
2
+
3
+ Add space between title and link.
4
+
5
+ ```diff
6
+ # @putout/plugin-apply-replace-all [![NPM version][NPMIMGURL]][NPMURL]
7
+
8
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-apply-replace-all.svg?style=flat&longCache=true
9
+ -[NPMURL]: https://npmjs.org/package/@putout/plugin-apply-replace-all"npm"
10
+ +[NPMURL]: https://npmjs.org/package/@putout/plugin-apply-replace-all "npm"
11
+
12
+ -[hello](https://google.com"Google")
13
+ +[hello](https://google.com "Google")
14
+ ```
@@ -0,0 +1,33 @@
1
+ export const name = 'split-link-with-title';
2
+
3
+ export const report = () => 'Split link with title';
4
+
5
+ export const fix = (node) => {
6
+ const [url, title] = node.url.split('"');
7
+
8
+ node.url = url;
9
+ node.title = title;
10
+ };
11
+
12
+ export const traverse = (tree, {push}) => {
13
+ for (const node of tree.children) {
14
+ const {
15
+ type,
16
+ url,
17
+ title,
18
+ } = node;
19
+
20
+ if (type === 'paragraph')
21
+ traverse(node, {
22
+ push,
23
+ });
24
+
25
+ if (!/link|definition/.test(type))
26
+ continue;
27
+
28
+ if (title || !url.includes('"'))
29
+ continue;
30
+
31
+ push(node);
32
+ }
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/processor-markdown",
3
- "version": "13.0.0",
3
+ "version": "13.1.1",
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",
@@ -48,7 +48,7 @@
48
48
  "c8": "^10.0.0",
49
49
  "eslint": "^10.0.0-alpha.0",
50
50
  "eslint-plugin-n": "^17.0.0",
51
- "eslint-plugin-putout": "^29.0.0",
51
+ "eslint-plugin-putout": "^30.0.0",
52
52
  "madcut": "^2.0.0",
53
53
  "madrun": "^12.0.0",
54
54
  "montag": "^1.2.1",