StirlingWestrup
(redirected from Profiles.Swestrup)
Stirling Westrup is a professional programmer. He has a PmWiki at http://sti.pooq.com.
Other Profiles
While I've been learning about PmWiki, I've come across useful information in a number of places, and I've put links here so I won't forget where they are:
Scott Connard - SaveAsDraft configuration info.
Recipes
I've started writing recipes for inclusion into PmWiki. Here's where I'm going to list them:
Traditional ASCII Markup.
I wanted to be able to use markup such as /italics/, *bold* and _underline_, as one often does in plain text discussions. It took quite a bit of work to come up with some definitions that didn't interfere with any of the standard or extended markups that I use on my wiki. So far, it seems to be working well though, and I may package eventually clean this up and package it as a Cookbook entry. For now, here's just my raw notes:
Warning: Although I thought I had tested this extensively before putting this here, experiences with using it in the field shows it has major problems. It will need to be rethought, and reworked. Sorry.
config.php:
## Add the traditional *bold*, /italic/ and _underscore_ notations
## from ASCII text. To reduce false matches, these come in two
## flavors. The first version only matches simple strings of
## underscore-separated words, and allows all three markups (provided
## the delimiters balance). Thus we have
##
## *bold_text*
## /italic_text/
## _underscored_text_
## */bold_italic/* BUT NOT */doesn't_balance*/
## /_*bold_italic_underscore*_/
##
## These need to be surrounded by whitespace, common English
## punctuation marks, or string terminators to be recognized. I wanted
## to have full punctuation support but PHP has no reasonable unicode
## support.
##
## For cases when the internal text needs to be more complex, or for
## when you need to place these directly inside or beside other markup
## (they only match when surrounded by whitespace, text-boundaries, or
## punctuation), enclose the text in '[]' brackets as well:
##
## [*Bob's Bold Text*]
## %foo%[*/bold italics, after a %foo%/*]
##
## $punc is what counts as 'normal punctuation' for purposes of detecting
## the beginning and ending of the wiki markup. Thus, if you add the
## character '@' to the list below then @/italic/ will render as italic,
## otherwise it will not.
$punc='"\'(),.:;?!`';
## $pat1 is the regular expression for the traditional markups
## (without square brackets)
$pat1=<<<EOL
/
(?<=^|(?<=[$punc]|\s)) # After a start of line, space or punctuation mark
([*_\/])([*_\/]?)([*_\/]?) # Up to three opening chars from the set [/_*]
(?!_)(\w+)(?<!_) # '_' separated words, beginning and ending with letters.
\\3\\2\\1 # Our opening chars again, in reverse order
(?=$|(?=[$punc]|\s)) # followed by end of line, space or punctuation marks
/ex
EOL;
## $pat2 is the regular expression for the version
## with square brackets.
$pat2=<<<EOL
/
\[ # opening square bracket.
([*_\/]) ([*_\/]?) ([*_\/]?) # up to three opening chars from [/_*]
(.*) # anything
\\3\\2\\1 # our opening chars in reverse order
\] # closing square bracket
/ex
EOL;
## fixtext takes the text delimited by the markup chars,
## and the three delimiters, and returns the replacement
## string.
function fixtext($txt,$r1,$r2,$r3)
{
$t = strtr($txt,"/_/"," ");
$a = array("/" => "i", "*" => "b", "_"=> "u");
$b = array_filter(array($r1,$r2,$r3));
foreach ($b as $k)
{
$q[$k] = true;
$t = "<$a[$k]>$t</$a[$k]>";
}
if( count($b) == count($q) )
return $t;
else
# return "FAIL";
return "$r1$r2$r3$txt$r3$r2$r1";
}
Markup("*_/", "inline", $pat1, 'fixtext("$4","$1","$2","$3")'); # */_bold_italic_underline*/_
Markup("[*_/", "inline", $pat2, 'fixtext("$4","$1","$2","$3")');