Skip to content

Commit 7f81648

Browse files
committed
Rebase to resolve merge conflicts
1 parent fc11a3b commit 7f81648

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

docs/userGuide/usingPlugins.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99

1010
# Using Plugins
1111

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.
1313

14-
**WARNING:** Plugins are executable programs. This means that they might contain malicious code that may damage your computer.
14+
<tip-box type="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.
1516

1617
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>
1719

1820
### Adding Plugins
1921

2022
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`:
2123

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.
2426

2527
For example:
2628

27-
```
29+
```json
2830
{
2931
...
3032
"plugins" : [
@@ -42,30 +44,31 @@ For example:
4244

4345
MarkBind plugins allow the user to mutate the page data (`html`) during the page compilation process.
4446

45-
![Markbind Rendering]({{baseUrl}}/images/rendering.png)
47+
![MarkBind Rendering]({{baseUrl}}/images/rendering.png)
4648

4749
MarkBind provides two entry points for modifying the page:
4850

4951
- Prerender: Called before MarkBind converts/renders the source from markdown to HTML.
5052
- Postrender: Called after the HTML is rendered.
5153

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:
5355

5456
- `content`: The intermediate content of the page data represented as a string.
5557
- For `preRender`, `content` will be the raw markdown of a `.md` file.
5658
- 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`.
5860

5961
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.
6062

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:
6264

6365
```js
6466
// myPlugin.js
6567

6668
const cheerio = module.parent.require('cheerio');
6769

6870
module.exports = {
71+
preRender: (content, siteContext) => content.replace('<Prerender Placeholder>', `${siteContext.pre}`),
6972
postRender: (content, siteContext) => {
7073
const $ = cheerio.load(content, { xmlMode: false });
7174
// Modify the page...
@@ -85,6 +88,7 @@ module.exports = {
8588
],
8689
"context" : {
8790
"myPlugin" : {
91+
"pre" : "<p>Hello</p>"
8892
"post" : "<p>Hello</p>"
8993
}
9094
}
@@ -95,7 +99,9 @@ module.exports = {
9599
// index.md
96100

97101
...
98-
<div id="my-div"></div>
102+
<div id="my-div">
103+
<Prerender Placeholder>
104+
</div>
99105
```
100106

101107
</div>

0 commit comments

Comments
 (0)