Commit c15c0990 authored by Thomas Parisot's avatar Thomas Parisot

feat(previewer): add beforePreview and afterPreview hooks

parent 458f4728
Pipeline #269 failed with stage
in 24 seconds
......@@ -117,6 +117,10 @@ New handlers can be registered from `import { registerHandlers } from 'pagedjs'`
Handlers have methods that correspond to the hooks for the parsing, layout and rendering of the Chunker and Polisher. Returning an promise or `async` function from a method in a handler will complete that task before continuing with the other registered methods for that hook.
```js
// Previewer
beforePreview(content, renderTo)
afterPreview(pages)
// Chunker
beforeParsed(content)
afterParsed(parsed)
......
import EventEmitter from "event-emitter";
import Hook from "../utils/hook";
import Chunker from "../chunker/chunker";
import Polisher from "../polisher/polisher";
......@@ -17,6 +18,8 @@ class Previewer {
// Hooks
this.hooks = {};
this.hooks.beforeAll = new Hook(this);
this.hooks.afterAll = new Hook(this);
// Handlers
this.handlers = this.initializeHandlers();
......@@ -119,6 +122,8 @@ class Previewer {
async preview(content, stylesheets, renderTo) {
await this.hooks.beforePreview.trigger(content, renderTo);
if (!content) {
content = this.wrapContent();
}
......@@ -143,6 +148,8 @@ class Previewer {
this.emit("rendered", flow);
await this.hooks.afterPreview.trigger(flow.pages);
return flow;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment