This is an old revision of the document!
Table of Contents
text (export / renderer plugin)
Compatible with DokuWiki
2008-05-05
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Similar to plaintext
Needed for bookcreator, odtsupport, searchtext
This plugin allows you to export a page to a plain text format usable as a simplistic document or to be used in further processing.
Download
- http://cobs.rollerorgans.com/plugins/text.zip – 2008-02-28, caching bugfix
- 2008-02-28, initial upload
Usage
To export a single page add the following parameter to the page URL:
<pagename>?do=export_text
To get a copy of rendered text in PHP (i.e. from a button or some other plugin) use:
global $ID; $ID = $id; //necessary for correct metadata handling $text = p_cached_output(wikiFN($id),'text');
Other plugins
The text renderer plugin was originally designed for use with the searchtext plugin, to provide both a basis for searching rendered text, and providing a rendered text snippet for displayed search result.
If you use other syntax plugins, their output may not appear correctly in the exported text unless:
- they specifically support the 'text' output format, or
- they support standard XHTML output and the text is suitable when stripped of its HTML markup
Discussion
To add a button to your template to access this plugin's output, try adding the following in your template at the point you would like the button to appear.
<?php echo html_button('text',$ID,'t',array('do' => 'export_text'),'get','export this page as text'); ?>
Note:
- 'text' will appear in the button, change as appropriate.
- 'export this page as text' will appear as a tooltip when you hover over the button. change as appropriate.
If you are not using a dev version or are on the latest stable use this code instead:
<?php echo html_btn('text',$ID,'t',array('do' => 'export_text'),'get','export this page as text'); ?>
Or if you like pretty icon links rather than buttons:
<a href="<?php echo exportlink($ID, 'text')?>"><img src="<?php echo DOKU_BASE?>lib/images/fileicons/txt.png" alt="Text Export"></a>
MBCS problem
In the textsearch result page, there is some line like :
Warning: cannot yet handle MBCS in html_entity_decode()! in /www/cyrille/lib/plugins/text/renderer.php on line 315
Is there somethine about utf8 or something like ?
— Cyrille Giquello 2009/01/29 16:21
Ok, I've updated PHP from version 4.4.9 to 5.2.6 and the problem is solved.
— Cyrille Giquello 2009/01/29 17:23
Since I don't want to lose searcheable content (when used with the Searchtext Plugin), I'd prefer to put the URL in if it contains additional information:
function _getLinkTitle($title, $default, & $isImage, $id=NULL) { global $conf; $isImage = false; if ( is_null($title) ) { if ($conf['useheading'] && $id) { $heading = p_get_first_heading($id,true); if ($heading) { return $heading; } } return $default; } else if ( is_string($title) ) { if (!is_null($default) && ($default != $title)) return $default." ".$title; else return $title; } else if ( is_array($title) ) { if (!is_null($default) && ($default != $title['title'])) return $default." ".$title['title']; else return $title['title']; } }
— Wilfried Goesgens 2010/02/23 15:45
Setting the right mimetype
in function document_start()
$metaheader['Content-Type'] = 'text/html; charset=utf-8';
should be replaced by
$metaheader['Content-Type'] = 'text/plain; charset=utf-8';
Or else a browser will render it really awful. — Wilfried Goesgens 2010/02/23 15:45
Fixing warning while running in the indexer
you will get Warning: Illegal offset type in isset or empty in dokuwiki/inc/parserutils.php on line 318 since
// function document_start()// calls p_set_metadata with an array; it actualy needs to be:
p_set_metadata($ID[0],$meta);
instead of
p_set_metadata($ID,$meta);