Skip to content

Commit 6d8226b

Browse files
committed
Changed the locallink() implementation from just inserting text to inserting a link to the corresponding heading.
1 parent b44e556 commit 6d8226b

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2015-07-09 LarsDW223
2+
3+
* Changed the locallink() implementation from just inserting text to inserting a link
4+
to the corresponding heading.
5+
16
2015-07-08 LarsDW223
27

38
* Added syntax tag for including a TOC in the exported ODT file.

plugin.info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
base odt
22
author Andreas Gohr, Aurelien Bompard, Florian Lamml, LarsDW223
33
email andi@splitbrain.org, aurelien@bompard.org, infor@florian-lamml.de
4-
date 2015-07-08
4+
date 2015-07-09
55
name Open Document Plugin
66
desc Export the current Wiki page to a OpenOffice ODT file
77
url http://www.dokuwiki.org/plugin:odt

renderer/book.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function finalize_ODTfile() {
6262
// Insert TOC (if required)
6363
$this->insert_TOC();
6464

65+
// Replace local link placeholders
66+
$this->insert_locallinks();
67+
6568
parent::finalize_ODTfile();
6669
}
6770

renderer/page.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ function document_end(){
279279
// Insert TOC (if required)
280280
$this->insert_TOC();
281281

282+
// Replace local link placeholders
283+
$this->insert_locallinks();
284+
282285
// Build the document
283286
$this->finalize_ODTfile();
284287
}
@@ -478,11 +481,11 @@ protected function insert_TOC() {
478481
$params = explode (',', $item);
479482

480483
// Only add the heading to the TOC if its <= $max_outline_level
481-
if ( $params [2] <= $max_outline_level ) {
482-
$level = $params [2];
484+
if ( $params [3] <= $max_outline_level ) {
485+
$level = $params [3];
483486
$toc .= '<text:p text:style-name="'.$p_styles [$level].'">';
484487
$toc .= '<text:a xlink:type="simple" xlink:href="#'.$params [0].'" text:style-name="'.$stylesLNames [$level].'" text:visited-style-name="'.$stylesLNames [$level].'">';
485-
$toc .= $params [1];
488+
$toc .= $params [2];
486489
$toc .= '<text:tab/>';
487490
$page++;
488491
$toc .= $page;
@@ -500,6 +503,12 @@ protected function insert_TOC() {
500503
$toc .= '<text:p text:style-name="pagebreak"/>';
501504
}
502505

506+
// Only for debugging
507+
//foreach ($this->toc as $item) {
508+
// $params = explode (',', $item);
509+
// $toc .= '<text:p>'.$params [0].'€'.$params [1].'€'.$params [2].'€'.$params [3].'</text:p>';
510+
//}
511+
503512
// Replace placeholder with TOC content.
504513
$this->doc = str_replace ('<text:table-of-content/>', $toc, $this->doc);
505514
}
@@ -534,8 +543,8 @@ protected function _buildTOCReferenceID($title) {
534543
* @param string $text the text to display
535544
* @param int $level the nesting level
536545
*/
537-
function toc_additem($refID, $text, $level) {
538-
$item = $refID.','.$text.','. $level;
546+
function toc_additem($refID, $hid, $text, $level) {
547+
$item = $refID.','.$hid.','.$text.','. $level;
539548
$this->toc[] = $item;
540549
}
541550

@@ -728,7 +737,7 @@ function header($text, $level, $pos){
728737

729738
// Do not add headings in frames
730739
if ( $this->in_div_as_frame == 0 ) {
731-
$this->toc_additem($TOCRef, $text, $level);
740+
$this->toc_additem($TOCRef, $hid, $text, $level);
732741
}
733742
}
734743

@@ -1422,6 +1431,37 @@ function externallink($url, $name = NULL) {
14221431
$this->_doLink($url,$name);
14231432
}
14241433

1434+
/**
1435+
* Replace local links with bookmark references or text
1436+
*/
1437+
protected function insert_locallinks() {
1438+
$matches = array();
1439+
if ( preg_match('/<locallink>.+<\/locallink>/', $this->doc, $matches) === 1 ) {
1440+
foreach ($matches as $match) {
1441+
$text = substr ($match, 11);
1442+
$text = str_replace ('</locallink>', '', $text);
1443+
$page = str_replace (' ', '_', $text);
1444+
1445+
$found = false;
1446+
foreach ($this->toc as $item) {
1447+
$params = explode (',', $item);
1448+
if ( $page == $params [1] ) {
1449+
$found = true;
1450+
$link = '<text:a xlink:type="simple" xlink:href="#'.$params [0].'">';
1451+
$link .= $text;
1452+
$link .= '</text:a>';
1453+
1454+
$this->doc = str_replace ($match, $link, $this->doc);
1455+
}
1456+
}
1457+
1458+
if ( $found == false ) {
1459+
$this->doc = str_replace ($match, $text, $this->doc);
1460+
}
1461+
}
1462+
}
1463+
}
1464+
14251465
/**
14261466
* Just print local links
14271467
*
@@ -1432,7 +1472,7 @@ function externallink($url, $name = NULL) {
14321472
*/
14331473
function locallink($hash, $name = NULL){
14341474
$name = $this->_getLinkTitle($name, $hash, $isImage);
1435-
$this->doc .= $name;
1475+
$this->doc .= '<locallink>'.$name.'</locallink>';
14361476
}
14371477

14381478
/**

0 commit comments

Comments
 (0)