text (export / renderer plugin)

text plugin by Todd Augsburger
Exports or Renders a page as plain text

Last updated on 2008-02-28. Provides Render.
Compatible with DokuWiki devel >2007-10-16.

Tagged with export, search.

    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.

    :!: You will need a recent development version of DokuWiki to make this work!

    Download

    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:

    1. they specifically support the 'text' output format, or
    2. 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);
     
    plugin/text.txt · Last modified: 2010/02/25 19:40 by 74.93.99.97
     
    Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
    Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
    WikiForumIRCBugsGitXRefTranslate