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 11import { remark } from 'remark' ;
2- import { is } from 'unist-util-is' ;
3- import replaceAllBetween from '..' ;
2+ import replaceAllBetween from '../index.js' ;
43
54const markdown = `
65# Hello World!
76
87This is a [Real page](https://google.com)
98
10- <!-- tabs:start -->
11-
12- #### **English**
13-
14- Hello!
15-
16- #### **French**
17-
18- Bonjour!
19-
20- #### **Italian**
9+ <!-- hello:start -->
2110
2211Ciao!
2312
24- <!-- tabs :end -->
13+ <!-- hello :end -->
2514
2615Testing
2716
2817# Test
2918
3019
31- <!-- tabs:start -->
32-
33- #### **English**
20+ <!-- hello:start -->
3421
3522Hello!
3623
37- #### **French**
38-
39- Bonjour!
40-
41- Telakjdsf
42-
43- asdf
44-
45- <!-- tabs:end -->
24+ <!-- hello:end -->
4625
4726# Testing
4827
@@ -75,12 +54,12 @@ const plugin = () => (tree) => {
7554 // `start` and `end` nodes to look for, and find between.
7655 const start = {
7756 type : 'html' ,
78- value : '<!-- tabs :start -->'
57+ value : '<!-- hello :start -->'
7958 } ;
8059
8160 const end = {
8261 type : 'html' ,
83- value : '<!-- tabs :end -->'
62+ value : '<!-- hello :end -->'
8463 } ;
8564
8665 // Get lists between `start` and `end`
@@ -89,25 +68,13 @@ const plugin = () => (tree) => {
8968 list . shift ( ) ;
9069 list . pop ( ) ;
9170
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!"
10974 }
110- ] ;
75+ }
76+
77+ return list ;
11178 } ) ;
11279
11380 // Return new tree
Original file line number Diff line number Diff line change 22 "name" : " unist-util-replace-between-example" ,
33 "type" : " module" ,
44 "dependencies" : {
5- "remark" : " ^14.0.1" ,
6- "unist-util-is" : " ^5.1.1"
5+ "remark" : " ^14.0.1"
76 }
87}
Original file line number Diff line number Diff line change 11{
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" ,
55 "main" : " index.js" ,
66 "engines" : {
77 "node" : " >=10"
You can’t perform that action at this time.
0 commit comments