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
Copy file name to clipboardExpand all lines: docs/userGuide/usingPlugins.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,16 @@
11
11
12
12
A plugin is a user defined extension that can add custom features to MarkBind. Markbind plugins are `js` scripts that are loaded and run during the page generation.
13
13
14
+
**WARNING:** Plugins are executable programs. This means that they might contain malicious code that may damage your computer.
15
+
16
+
Only run plugins from people that you trust. Do not run the plugin if the source/origin of the plugin cannot be ascertained.
17
+
14
18
### Adding Plugins
15
19
16
-
Plugins are stored in the `_markbind/plugins` folder which is generated on `init`. To use a plugin, place the `js`file in the `_markbind/plugins` folder and add the following options to the site configuration:
20
+
Plugins are stored in the `_markbind/plugins` folder which is generated on `init`. To use a plugin, place the `js`source of the plugin in the `_markbind/plugins` folder and add the following options to `site.json`:
17
21
18
22
-`plugins`: An array of plugin names to use
19
-
-`context`: An object mapping plugin name to data provided to the plugin. Each plugin can have its own custom data.
23
+
-`context`: An object containing lists of parameters passed to each individual plugin.
20
24
21
25
For example:
22
26
@@ -42,8 +46,8 @@ MarkBind plugins allow the user to mutate the page data (`html`) during the page
42
46
43
47
MarkBind provides two entry points for modifying the page:
44
48
45
-
- Prerender: Called before any markbind rendering is done on the site. Markbind rendering refers to the conversion of markdown to valid HTML.
46
-
- Postrender: Called after all markbind rendering is done on the site.
49
+
- Prerender: Called before MarkBind converts/renders the source from markdown to HTML.
50
+
- Postrender: Called after the HTML is rendered.
47
51
48
52
These are controlled by specifying the `preRender` and `postRender` functions in the plugin `js`. Each function takes in two parameters:
49
53
@@ -52,9 +56,9 @@ These are controlled by specifying the `preRender` and `postRender` functions in
52
56
- For `postRender`, `content` will be the compiled `.html` file.
53
57
-`siteContext`: Any other data to be provided to the plugin. This can be specified in the `site.json`.
54
58
55
-
Markbind will call these two functions with the respective content, and retrieve a string data that is used for the next step of the compilation process.
59
+
MarkBind will call these two functions with the respective content, and retrieve a string data that is used for the next step of the compilation process.
56
60
57
-
A plugin will typically follow a format similar to this one:
61
+
An example of a plugin is shown below. The plugin appends a paragraph of text to a specific div in the markdown files:
58
62
59
63
```js
60
64
// myPlugin.js
@@ -80,7 +84,7 @@ module.exports = {
80
84
"myPlugin"
81
85
],
82
86
"context": {
83
-
"plugin1": {
87
+
"myPlugin": {
84
88
"post":"<p>Hello</p>"
85
89
}
86
90
}
@@ -94,6 +98,4 @@ module.exports = {
94
98
<div id="my-div"></div>
95
99
```
96
100
97
-
The above plugin appends a paragraph of text to a div in the `index.md`.
0 commit comments