File tree Expand file tree Collapse file tree 3 files changed +17
-51
lines changed Expand file tree Collapse file tree 3 files changed +17
-51
lines changed Original file line number Diff line number Diff line change 1
1
import { remark } from 'remark' ;
2
- import { is } from 'unist-util-is' ;
3
- import replaceAllBetween from '..' ;
2
+ import replaceAllBetween from '../index.js' ;
4
3
5
4
const markdown = `
6
5
# Hello World!
7
6
8
7
This is a [Real page](https://google.com)
9
8
10
- <!-- tabs:start -->
11
-
12
- #### **English**
13
-
14
- Hello!
15
-
16
- #### **French**
17
-
18
- Bonjour!
19
-
20
- #### **Italian**
9
+ <!-- hello:start -->
21
10
22
11
Ciao!
23
12
24
- <!-- tabs :end -->
13
+ <!-- hello :end -->
25
14
26
15
Testing
27
16
28
17
# Test
29
18
30
19
31
- <!-- tabs:start -->
32
-
33
- #### **English**
20
+ <!-- hello:start -->
34
21
35
22
Hello!
36
23
37
- #### **French**
38
-
39
- Bonjour!
40
-
41
- Telakjdsf
42
-
43
- asdf
44
-
45
- <!-- tabs:end -->
24
+ <!-- hello:end -->
46
25
47
26
# Testing
48
27
@@ -75,12 +54,12 @@ const plugin = () => (tree) => {
75
54
// `start` and `end` nodes to look for, and find between.
76
55
const start = {
77
56
type : 'html' ,
78
- value : '<!-- tabs :start -->'
57
+ value : '<!-- hello :start -->'
79
58
} ;
80
59
81
60
const end = {
82
61
type : 'html' ,
83
- value : '<!-- tabs :end -->'
62
+ value : '<!-- hello :end -->'
84
63
} ;
85
64
86
65
// Get lists between `start` and `end`
@@ -89,25 +68,13 @@ const plugin = () => (tree) => {
89
68
list . shift ( ) ;
90
69
list . pop ( ) ;
91
70
92
- const headerIndexes = list
93
- . map ( ( node , i ) => is ( node , { type : 'heading' } ) && i )
94
- . filter ( Number . isInteger ) ;
95
-
96
- const sections = getSections ( list , headerIndexes ) ;
97
-
98
- const tabNodes = sections . map ( ( section ) => {
99
- return {
100
- type : 'html' ,
101
- value : section . range
102
- } ;
103
- } ) ;
104
-
105
- return [
106
- {
107
- type : 'element' ,
108
- children : tabNodes
71
+ for ( let node of list ) {
72
+ for ( let child of node . children ) {
73
+ child . value = child . value + "! This is cool!"
109
74
}
110
- ] ;
75
+ }
76
+
77
+ return list ;
111
78
} ) ;
112
79
113
80
// Return new tree
Original file line number Diff line number Diff line change 2
2
"name" : " unist-util-replace-between-example" ,
3
3
"type" : " module" ,
4
4
"dependencies" : {
5
- "remark" : " ^14.0.1" ,
6
- "unist-util-is" : " ^5.1.1"
5
+ "remark" : " ^14.0.1"
7
6
}
8
7
}
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " unist-util-find -all-between" ,
3
- "version" : " 2 .1.0" ,
4
- "description" : " Utility to find nodes between two nodes" ,
2
+ "name" : " unist-util-replace -all-between" ,
3
+ "version" : " 0 .1.0" ,
4
+ "description" : " Utility to replace nodes between all instances of two nodes" ,
5
5
"main" : " index.js" ,
6
6
"engines" : {
7
7
"node" : " >=10"
You can’t perform that action at this time.
0 commit comments