You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom tags are now supported as of 0.4.0 of markdown-include. Adding custom tags to your documentation is quite easy to do.
548
+
Plugins are now supported as of 0.4.0 of markdown-include. Adding plugins to markdown-include to facilitate the transformation of custom tags is quite trivial.
547
549
548
-
Custom tags can only be used when markdown-include is being required as a module. If you wish to make this available via the command line, you must require markdown-include in a node module and call it from the command line.
550
+
Plugins are best used when markdown-include is being required as a module. If you wish to make this available via the command line, you must require markdown-include in a node module and call it from the command line.
549
551
550
552
## Tutorial
551
553
552
-
Let's pretend we want to add a custom tag called `!myTag` that follows the pattern of `#phrase !myTag`. We need to register the custom tag with markdown-include in it's `customTags` array.
554
+
Let's pretend we want to add a custom tag called `!myTag` that follows the pattern of `#phrase !myTag`. All we need to do is register the plugin with markdown-include
553
555
554
556
First, require markdown-include:
555
557
556
558
```javascript
557
559
var markdownInclude =require('markdown-include');
558
560
```
559
561
560
-
Second, register your tag with your desired replacement. You can replace your tag with either another string or use a function to do your desired work. This is done with objects added to an array, like so:
562
+
Second, register your plugin with with your desired pattern to match and desired replacement. You can replace your tag with another string to do your desired work:
561
563
562
564
```javascript
563
565
var markdownInclude =require('markdown-include');
564
-
markdownInclude.customTags.push({
566
+
markdownInclude.registerPlugin({
565
567
pattern:/^#.+ !myTag/gm,
566
-
replacement:'myString!'
568
+
replace:'myString!'
567
569
});
568
570
```
569
571
570
-
`pattern` is the regular expression that should be looked for. `replacement` is your desired replacement for the tag once it's found. In the example above, we're just replacing our tag with a string. If you would rather use a function, you can do this like so:
572
+
In the example above, we're just replacing our tag with a string. If you would rather use a function, you can do this like so (you must return a value to replace with):
571
573
572
574
```javascript
573
575
var markdownInclude =require('markdown-include');
574
-
markdownInclude.customTags.push({
576
+
markdownInclude.registerPlugin({
575
577
pattern:/^#.+ !myTag/gm,
576
-
replacement:function (tag) {
578
+
replace:function (tag) {
577
579
// do something with tag...
580
+
return'myString!'
578
581
}
579
582
});
580
583
```
581
584
582
-
This gives you free range to do whatever you want with the tag in question. Once the tag is encountered markdown-include will run the function.
585
+
`pattern` is the regular expression that should be looked for. `replace` is your desired replacement for the tag once it's found.
586
+
587
+
This gives you free range to do whatever you want with the tag you want to replace. Once the tag is encountered markdown-include will run the function.
583
588
584
589
After the tag and it's replacement is registed, it's business as usual:
Plugins are now supported as of 0.4.0 of markdown-include. Adding plugins to markdown-include to facilitate the transformation of custom tags is quite trivial.
4
+
5
+
Plugins are best used when markdown-include is being required as a module. If you wish to make this available via the command line, you must require markdown-include in a node module and call it from the command line.
6
+
7
+
## Tutorial !heading
8
+
9
+
Let's pretend we want to add a custom tag called `!myTag` that follows the pattern of `#phrase !myTag`. All we need to do is register the plugin with markdown-include
10
+
11
+
First, require markdown-include:
12
+
13
+
```javascript
14
+
var markdownInclude =require('markdown-include');
15
+
```
16
+
17
+
Second, register your plugin with with your desired pattern to match and desired replacement. You can replace your tag with another string to do your desired work:
18
+
19
+
```javascript
20
+
var markdownInclude =require('markdown-include');
21
+
markdownInclude.registerPlugin({
22
+
pattern:/^#.+ !myTag/gm,
23
+
replace:'myString!'
24
+
});
25
+
```
26
+
27
+
In the example above, we're just replacing our tag with a string. If you would rather use a function, you can do this like so (you must return a value to replace with):
28
+
29
+
```javascript
30
+
var markdownInclude =require('markdown-include');
31
+
markdownInclude.registerPlugin({
32
+
pattern:/^#.+ !myTag/gm,
33
+
replace:function (tag) {
34
+
// do something with tag...
35
+
return'myString!'
36
+
}
37
+
});
38
+
```
39
+
40
+
`pattern` is the regular expression that should be looked for. `replace` is your desired replacement for the tag once it's found.
41
+
42
+
This gives you free range to do whatever you want with the tag you want to replace. Once the tag is encountered markdown-include will run the function.
43
+
44
+
After the tag and it's replacement is registed, it's business as usual:
0 commit comments