GitbookIO / plugin

Sample plugin for GitBook
Apache License 2.0
66 stars 56 forks source link

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

Open bguiz opened 10 years ago

bguiz commented 10 years ago

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));
bguiz commented 10 years ago

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:

https://github.com/GitbookIO/plugin-ga/commit/f48257e0ee0d4838aeb535aaa473848321d30d81#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.

bguiz commented 10 years ago

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.