PagePmSyntax

Summary: Highlight a full PmWiki source page
Version: 20220817
Prerequisites: PmWiki 2.3.x
Status: Experimental
Maintainer: Petko
License: Public Domain
Categories: PmSyntax Layout
Users: +2 (view / edit)
Discussion: PagePmSyntax-Talk?

Questions answered by this recipe

With PmSyntax, is it possible to automatically highlighting source (?action=source)?

Description

Highlight a full PmWiki source page.

This adds a new action "pmsyntax" which outputs the wiki source text of the page with syntax highlighting by PmSyntax.

Installation

Add to config.php:

$HandleActions['pmsyntax'] = 'HandlePmSyntax';
function HandlePmSyntax($pagename, $auth='read') {
  global $EnablePmSyntax, $PageStartFmt, $PageEndFmt;
  $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
  if (!$page) { Abort("?unable to read $pagename"); }

  $text = "<div class='pmhlt'><pre style='white-space: pre-wrap;'>" 
    . str_replace('$', '&#x24;', PHSC($page['text'])).'</pre></div>';

  $fmt = array( &$PageStartFmt, $text, &$PageEndFmt);

  $EnablePmSyntax = 1;
  DisableSkinParts('header footer left right action title');
  PrintFmt($pagename,$fmt);
}

Configuration

To intercept and handle the ?action=source requests, you can add the following to the above block:

$HandleActions['source'] = 'HandlePmSyntax';

Note, however, that the original action=source outputs plain text, while the new one outputs HTML to be transformed by the browser. If you have tools that query the wiki for action=source and expect plain text, changing the output to HTML may break them.

Usage

Browse to Page?action=pmsyntax.

The recipe is enabled on PmWiki.org, feel free to test it on any page, for example PmWiki.DocumentationIndex?action=pmsyntax.

Notes

To do / some day / maybe

Add markup to include in a normal wiki page the highlighted source of another page.

Change log / Release notes

  • 20220817 - first public release, ready to be tested.

See also

Contributors

Written and maintained by Petko.

Comments

See discussion at PagePmSyntax-Talk?

User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.