...
 
Commits (2)
......@@ -111,6 +111,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.beforePreview = new Hook(this);
this.hooks.afterPreview = new Hook(this);
// default size
this.size = {
......@@ -116,6 +119,8 @@ class Previewer {
async preview(content, stylesheets, renderTo) {
await this.hooks.beforePreview.trigger(content, renderTo);
if (!content) {
content = this.wrapContent();
}
......@@ -142,6 +147,8 @@ class Previewer {
this.emit("rendered", flow);
await this.hooks.afterPreview.trigger(flow.pages);
return flow;
}
}
......