DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:stickyexporthtml

Sticky "do=export_html"

Concept

You can append “do=export_html” or “do=export_xhtml” to a DokuWiki URL to view just the HTML for the page, without the DokuWiki buttons and whatnot. The problem is that if you click a link in the HTML page, it doesn't include the “do=export_html”, so the linked page isn't plain HTML.

With these changes, once you've specified “do=export_html” to any page, clicking the links on that page will keep the “export_html” action.

My original inspiration was to allow extraction of DokuWiki contents as HTML for conversion to PDF, CHM or whatever.

Instructions

In Version 2006-03-09b

Change #1

In inc/parser/xhtml.php, internallink function, around line 530, insert this code before the “output formatted” comment near the end of the function:

        global $ACT;
        if ($ACT == 'export_xhtml') {
          if (strpos($link['url'],'?'))
            $link['action']='&do='.$ACT;
          else
            $link['action']='?do='.$ACT;
        } else {
          $link['action']='';
        }

That change adds the “export_xhtml” action to the link “action” field if that was the action by which the current page was loaded. You don't need to handle “export_html” separately, because it gets translated to “export_xhtml” somewhere else.

And this runs for different actions:

     if ($ACT == 'export_html' || $ACT == 'export_xhtml' || $ACT == 'export_xhtmlbody') {

Change #2

Further down in xhtml.php, function _formatLink, around line 870, insert the following code just before the “remove double encodings in titles” comment:

        $link['url'] = $link['url'].$link['action'];

That change appends the action to every internal link, making it “sticky”.

Change #3

In inc/parserutils.php, p_cached_xhtml function, around line 130, change:

  $cache  = getCacheName($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.xhtml');

to:

  global $ACT;
  $cache  = getCacheName($file.$ACT.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.xhtml');

or in inc/cache.php change to:

    if ($mode == 'html' || $mode == 'xhtml' || $mode == 'xhtmlbody') {
     parent::cache($file.$mode.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);
    } else {
     parent::cache($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.'.$mode);
    }

The idea is to use a different cache file for “export_html” vs. not. Without this change I found that once you'd loaded a page with “export_html”, subsequent attempts to load the page normally would result in the HTML-only version.

tips/stickyexporthtml.txt · Last modified: 2010-11-17 09:55 by 188.195.45.26