GitbookIO / plugin

Sample plugin for GitBook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`page` hook: `page.content` is a string, not a list of parsed sections

bguiz opened this issue · comments

hook.page claims that:

        // page.content is a list of parsed sections

See; https://github.com/GitbookIO/plugin/blob/master/index.js#L59

However, this is not the case - page.content really is just a string containing the markdown for the currently processed input file; which makes the page hook no different from the page:before hook. When implementing a plugin, add the following statement to each of the hooks to verify.

        console.log('typeof page.content:', (typeof page.content));

The use case that I am trying to satisfy is a means to add HTML fragments to the page after the markdown has been processed.

This can currently be achieved using the book.html.body:end hook:

GitbookIO/plugin-ga@f48257e#diff-168726dbe96b3ce427e7fedce31bb0bcR8

... except that I would like to insert within each page content (not at the close of the body tag, as they will not not visible).
Within <div class="page-inner"> would be great.

I have managed to work around it in the plugin I was creating:

https://github.com/bguiz/gitbook-plugin-share

... so you can de-prioritise this for now.