diff --git a/manual/conversion.rst b/manual/conversion.rst index 5576209e01..ad7440e99f 100644 --- a/manual/conversion.rst +++ b/manual/conversion.rst @@ -840,7 +840,7 @@ template:: This will display the title at the left and the author at the right, in a font size smaller than the main text. -Finally, you can also use the current section in templates, as shown below:: +You can also use the current section in templates, as shown below::

_SECTION_

@@ -850,6 +850,12 @@ Outline). If the document has no table of contents then it will be replaced by empty text. If a single PDF page has multiple sections, the first section on the page will be used. +You can even use javascript inside the header and footer templates, for +example, the following template will cause page numbers to start at 4 instead +of 1:: + +

+ .. note:: When adding headers and footers make sure you set the page top and bottom margins to large enough values, under the Page Setup section of the conversion dialog. diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index e404bffba2..69db556d5f 100644 Binary files a/resources/compiled_coffeescript.zip and b/resources/compiled_coffeescript.zip differ diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 946edd619b..8ed5ae0da1 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -8,6 +8,10 @@ log = window.calibre_utils.log +runscripts = (parent) -> + for script in parent.getElementsByTagName('script') + eval(script.text || script.textContent || script.innerHTML || '') + class PagedDisplay # This class is a namespace to expose functions via the # window.paged_display object. The most important functions are: @@ -238,8 +242,10 @@ class PagedDisplay section = py_bridge.section() if this.header != null this.header.innerHTML = this.header_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"") + runscripts(this.header) if this.footer != null this.footer.innerHTML = this.footer_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"") + runscripts(this.footer) fit_images: () -> # Ensure no images are wider than the available width in a column. Note