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

From 2.3.35, this functionality is has been incorporated in the core, simply call ?action=source&highlight=1 to output a HTML page with the wiki source highlighted.

Questions answered by this recipe

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


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.


PmWiki 2.3.35 or newer: this has been enabled in the core.

Before PmWiki 2.3.35, 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');


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

PmWiki 2.3.35 or newer:
if($action == 'source' && !isset($_REQUEST['highlight'])) $_REQUEST['highlight'] = 1;

Before PmWiki 2.3.35:
$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.


PmWiki 2.3.35 or newer: Browse to Page?action=source&highlight=1.

Before PmWiki 2.3.35: Browse to Page?action=pmsyntax.

The function is enabled on, feel free to test it on any page, for example PmWiki.DocumentationIndex?action=source&highlight=1.


To do / some day / maybe

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

Change log / Release notes

  • 20240613 - added to the core ?action=source for PmWiki 2.3.35. If you upgrade, you can remove this recipe.
  • 20220817 - first public release, ready to be tested.

See also


Written and maintained by Petko.


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.