@@ -76,6 +76,8 @@ class renderer_plugin_odt_page extends Doku_Renderer {
7676 protected $ refIDCount = 0 ;
7777 /** @var pageBookmark */
7878 protected $ pageBookmark = NULL ;
79+ /** @var pagebreak */
80+ protected $ pagebreak = false ;
7981
8082 /**
8183 * Automatic styles. Will always be added to content.xml and styles.xml.
@@ -648,8 +650,8 @@ protected function insert_TOC() {
648650
649651 // Add a pagebreak if required.
650652 if ( (is_numeric ($ pagebreak ) && $ pagebreak ) || $ pagebreak == 'true ' ) {
651- $ this ->createPagebreakStyle ();
652- $ toc .= '<text:p text:style-name="pagebreak "/> ' ;
653+ $ style_name = $ this ->createPagebreakStyle (NULL , false );
654+ $ toc .= '<text:p text:style-name=" ' . $ style_name . ' "/> ' ;
653655 }
654656
655657 // Only for debugging
@@ -854,6 +856,10 @@ function p_open($style=NULL){
854856 }
855857 if (!$ this ->in_paragraph ) { // opening a paragraph inside another paragraph is illegal
856858 $ this ->in_paragraph = true ;
859+ if ( $ this ->pagebreak ) {
860+ $ style = $ this ->createPagebreakStyle ($ style );
861+ $ this ->pagebreak = false ;
862+ }
857863 $ this ->doc .= '<text:p text:style-name=" ' .$ style .'"> ' ;
858864 }
859865
@@ -909,7 +915,12 @@ function header($text, $level, $pos){
909915 $ this ->p_close ();
910916 $ hid = $ this ->_headerToLink ($ text ,true );
911917 $ TOCRef = $ this ->_buildTOCReferenceID ($ text );
912- $ this ->doc .= '<text:h text:style-name=" ' .$ this ->styleset ->getStyleName ('heading ' .$ level ).'" text:outline-level=" ' .$ level .'"> ' ;
918+ $ style = $ this ->styleset ->getStyleName ('heading ' .$ level );
919+ if ( $ this ->pagebreak ) {
920+ $ style = $ this ->createPagebreakStyle ($ style );
921+ $ this ->pagebreak = false ;
922+ }
923+ $ this ->doc .= '<text:h text:style-name=" ' .$ style .'" text:outline-level=" ' .$ level .'"> ' ;
913924
914925 // Insert page bookmark if requested and not done yet.
915926 if ( !empty ($ this ->pageBookmark ) ) {
@@ -939,19 +950,32 @@ function linebreak() {
939950 $ this ->doc .= '<text:line-break/> ' ;
940951 }
941952
942- protected function createPagebreakStyle () {
943- if ( empty ($ this ->autostyles ['pagebreak ' ]) ) {
944- $ this ->autostyles ['pagebreak ' ] = '<style:style style:name="pagebreak" style:family="paragraph"><style:paragraph-properties fo:break-before="page"/></style:style> ' ;
953+ protected function createPagebreakStyle ($ parent =NULL ,$ before =true ) {
954+ $ style_name = 'pagebreak ' ;
955+ $ attr = 'fo:break-before ' ;
956+ if ( !$ before ) {
957+ $ style_name .= '_after ' ;
958+ $ attr = 'fo:break-after ' ;
959+ }
960+ if ( !empty ($ parent ) ) {
961+ $ style_name .= '_ ' .$ parent ;
962+ }
963+ if ( empty ($ this ->autostyles [$ style_name ]) ) {
964+ $ this ->autostyles [$ style_name ] = '<style:style style:name=" ' .$ style_name .'" style:family="paragraph" style:parent-style-name=" ' .$ parent .'"><style:paragraph-properties ' .$ attr .'="page"/></style:style> ' ;
945965
946966 // Save paragraph style name in 'Do not delete array'!
947- $ this ->preventDeletetionStyles [] = ' pagebreak ' ;
967+ $ this ->preventDeletetionStyles [] = $ style_name ;
948968 }
969+ return $ style_name ;
949970 }
950971
951972 function pagebreak () {
952- $ this ->createPagebreakStyle ();
973+ // Only set marker to insert a pagebreak on "next occasion".
974+ // The pagebreak will then be inserted in the next call to p_open() or header().
975+ // The style will be a "pagebreak" style with the paragraph or header style as the parent.
976+ // This prevents extra empty lines after the pagebreak.
953977 $ this ->p_close ();
954- $ this ->doc .= ' <text:p text:style-name="pagebreak"/> ' ;
978+ $ this ->pagebreak = true ;
955979 }
956980
957981 function strong_open () {
0 commit comments