@@ -73,6 +73,8 @@ class renderer_plugin_odt_page extends Doku_Renderer {
7373 protected $ preventDeletetionStyles = array ();
7474 /** @var refIDCount */
7575 protected $ refIDCount = 0 ;
76+ /** @var pageBookmark */
77+ protected $ pageBookmark = NULL ;
7678
7779 /**
7880 * Automatic styles. Will always be added to content.xml and styles.xml.
@@ -259,7 +261,7 @@ function document_start() {
259261 header ('Content-Disposition: attachment; filename=" ' .$ output_filename .'"; ' );
260262 }
261263
262- $ this ->insert_bookmark ($ ID );
264+ $ this ->set_page_bookmark ($ ID );
263265 }
264266
265267 /**
@@ -837,6 +839,12 @@ function p_open($style=NULL){
837839 $ this ->in_paragraph = true ;
838840 $ this ->doc .= '<text:p text:style-name=" ' .$ style .'"> ' ;
839841 }
842+
843+ // Insert page bookmark if requested and not done yet.
844+ if ( !empty ($ this ->pageBookmark ) ) {
845+ $ this ->insert_bookmark ($ this ->pageBookmark , false );
846+ $ this ->pageBookmark = NULL ;
847+ }
840848 }
841849
842850 function p_close (){
@@ -851,13 +859,28 @@ function p_close(){
851859 *
852860 * @param string $id ID of the bookmark
853861 */
854- function insert_bookmark ($ id ){
855- $ this ->p_open ();
862+ function insert_bookmark ($ id ,$ open_paragraph =true ){
863+ if ($ open_paragraph ) {
864+ $ this ->p_open ();
865+ }
856866 $ this ->doc .= '<text:bookmark text:name=" ' .$ id .'"/> ' ;
857- $ this ->p_close ();
858867 $ this ->bookmarks [] = $ id ;
859868 }
860869
870+ /**
871+ * Set bookmark for the start of the page. This just saves the title temporarily.
872+ * It is then to be inserted in the first header or paragraph.
873+ *
874+ * @param string $id ID of the bookmark
875+ */
876+ function set_page_bookmark ($ id ){
877+ if ( $ this ->in_paragraph ) {
878+ $ this ->insert_bookmark ($ id );
879+ } else {
880+ $ this ->pageBookmark = $ id ;
881+ }
882+ }
883+
861884 /**
862885 * Render a heading
863886 *
@@ -870,6 +893,13 @@ function header($text, $level, $pos){
870893 $ hid = $ this ->_headerToLink ($ text ,true );
871894 $ TOCRef = $ this ->_buildTOCReferenceID ($ text );
872895 $ this ->doc .= '<text:h text:style-name=" ' .$ this ->styleset ->getStyleName ('heading ' .$ level ).'" text:outline-level=" ' .$ level .'"> ' ;
896+
897+ // Insert page bookmark if requested and not done yet.
898+ if ( !empty ($ this ->pageBookmark ) ) {
899+ $ this ->insert_bookmark ($ this ->pageBookmark , false );
900+ $ this ->pageBookmark = NULL ;
901+ }
902+
873903 $ this ->doc .= '<text:bookmark-start text:name=" ' .$ TOCRef .'"/> ' ;
874904 $ this ->doc .= '<text:bookmark-start text:name=" ' .$ hid .'"/> ' ;
875905 $ this ->doc .= $ this ->_xmlEntities ($ text );
0 commit comments