Learn about DokuWiki
Learn about DokuWiki
The following script takes DokuWiki-formatted text (wikitext) as input, and outputs the resulting (XHTML) render content. It is useful for pipes and generating content dynamically. This was posted somewhere around the DokuWiki forums or IRC channel. Its authorship may be lost in time but as this is an useful script I've pasted it here in case it is needed.
<?php if ('cli' != php_sapi_name()) die(); ini_set('memory_limit','128M'); if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); define('NOSESSION',1); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/parserutils.php'); $source = stream_get_contents(STDIN); $info = array(); echo p_render('xhtml',p_get_instructions($source),$info); ?>
bin/folder (alongside the indexer).
From the command line shell:
php $PATH_TO_DOKUWIKI/bin/dokucli.php < input.txt > output.html ... or some_command_that_writes_wikicode input | php $PATH_TO_DOKUWIKI/bin/dokucli.php
$PATH_TO_DOKUWIKIis, of course, the Path to your DokuWiki.
outputare optional (the script reads from the Standard Input and writes to the Standard Output)
If you execute the script without parameters (to type in to the standard input directly), remember that the input finishes with your platform's “end-of-file” marker, that is CTRL+D in Unix and CTRL-Z in Windows.
If someone could discover the authorship of this code snippet in order to credit it accordingly, I at least would be very happy. — ryan.chappelle 2011/01/03 20:02
Here's a shell script that I've found useful for passing documents to the PHP files. I named it doku2html and put it in the path. –Donald Merand 07.03.2011 - http://www.explo.org
You use it like this:
doku2html file1 #... or doku2html file1 file2 file3... #... or some_command_that_writes_wikicode_input | doku2html #... to output to a file instead of STDOUT: doku2html file1 > output_file.html #just make sure that doku2html is in your path somewhere!
If you want to make the doku2html file executable right from the command line, you could type:
chmod 775 doku2html
The advantage of using this script is that you can easily pass multiple files, which are concatenated with a blank space between them. Input that's not a valid file is ignored. If no parameters are passed, use STDIN just like the PHP script above.
#!/bin/bash #Author: Donald L. Merand #path to the php file to run dokuwiki parsing from the CLI phpcli=path_to_dokuwiki/bin/dokucli.php #if parameters are not empty, assume files have been passed if [ $# -gt 0 ] then for file in "$@" do #ignore any non-files that are passed as parameters if [ -f "$file" ] then cat "$file" echo #line break between files fi done | # ^ note the pipe #now make one big HTML document out of whatever is passed php $phpcli else #read from stdin php $phpcli fi