Skip to content

Commit

Permalink
Update code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Mar 13, 2022
1 parent a031405 commit 70011e2
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions docs/write-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ window.$docsify = {

Alternatively, a plugin can be stored in a separate file and "installed" using a standard `<script>` tag.

```html
<script src="path/to/docsify-plugin-myplugin.js"></script>
```

```js
(function () {
var myPlugin = function (hook, vm) {
Expand All @@ -37,6 +33,10 @@ Alternatively, a plugin can be stored in a separate file and "installed" using a
})();
```

```html
<script src="docsify-plugin-myplugin.js"></script>
```

## Template

Below is a plugin template with placeholders for all available lifecycle hooks.
Expand All @@ -62,14 +62,14 @@ Below is a plugin template with placeholders for all available lifecycle hooks.
});

// Invoked on each page load before new markdown is transformed to HTML.
// See beforeEach() documentation for asynchronous tasks.
// Supports asynchronous tasks (see beforeEach documentation for details).
hook.beforeEach(function (markdown) {
// ...
return markdown;
});

// Invoked on each page load after new markdown has been transformed to HTML.
// See afterEach() documentation for asynchronous tasks.
// Supports asynchronous tasks (see afterEach documentation for details).
hook.afterEach(function (html) {
// ...
return html;
Expand Down Expand Up @@ -131,16 +131,13 @@ For asynchronous tasks, the hook function accepts a `next` callback as a second

```js
hook.beforeEach(function (markdown, next) {
// Asynchronous task (example)
setTimeout(function () {
try {
// ...
} catch (err) {
// ...
} finally {
next(markdown);
}
}, 1000);
try {
// Async task(s)...
} catch (err) {
// ...
} finally {
next(markdown);
}
});
```

Expand All @@ -159,16 +156,13 @@ For asynchronous tasks, the hook function accepts a `next` callback as a second

```js
hook.afterEach(function (html, next) {
// Asynchronous task (example)
setTimeout(function () {
try {
// ...
} catch (err) {
// ...
} finally {
next(markdown);
}
}, 1000);
try {
// Async task(s)...
} catch (err) {
// ...
} finally {
next(markdown);
}
});
```

Expand Down

0 comments on commit 70011e2

Please sign in to comment.