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
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,22 +9,24 @@
9
9
10
10
# Using Plugins
11
11
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.
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.
14
+
<tip-boxtype="warning">
15
+
**WARNING:** Plugins are executable programs that can be written by anyone. This means that they might contain malicious code that may damage your computer.
15
16
16
17
Only run plugins from people that you trust. Do not run the plugin if the source/origin of the plugin cannot be ascertained.
18
+
</tip-box>
17
19
18
20
### Adding Plugins
19
21
20
22
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`:
21
23
22
-
-`plugins`: An array of plugin names to use
23
-
-`context`: An object containing lists of parameters passed to each individual plugin.
24
+
-`plugins`: An array of plugin names to use.
25
+
-`context`: A mapping of a list of parameters passed to each individual plugin.
24
26
25
27
For example:
26
28
27
-
```
29
+
```json
28
30
{
29
31
...
30
32
"plugins" : [
@@ -42,30 +44,31 @@ For example:
42
44
43
45
MarkBind plugins allow the user to mutate the page data (`html`) during the page compilation process.
MarkBind provides two entry points for modifying the page:
48
50
49
51
- Prerender: Called before MarkBind converts/renders the source from markdown to HTML.
50
52
- Postrender: Called after the HTML is rendered.
51
53
52
-
These are controlled by specifying the `preRender` and `postRender` functions in the plugin `js`. Each function takes in two parameters:
54
+
These are controlled by specifying the `preRender()` and `postRender()` functions in the plugin `js`. Each function takes in two parameters:
53
55
54
56
-`content`: The intermediate content of the page data represented as a string.
55
57
- For `preRender`, `content` will be the raw markdown of a `.md` file.
56
58
- For `postRender`, `content` will be the compiled `.html` file.
57
-
-`siteContext`: Any other data to be provided to the plugin. This can be specified in the `site.json`.
59
+
-`siteContext`: User provided parameters for the plugin. This can be specified in the `site.json`.
58
60
59
61
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.
60
62
61
-
An example of a plugin is shown below. The plugin appends a paragraph of text to a specific div in the markdown files:
63
+
An example of a plugin is shown below. The plugin shows two ways of appending a paragraph of text to a specific div in the markdown files:
0 commit comments