Pseudo-formatters: one-time generated content
I'd like to discuss the idea - already suggested in the WakkaWiki community - of adding to Wikka a set of pseudo-formatters, taking care of one-time content generation. Whereas actual formatters interpret Wikka markup stored in the DB, pseudo-formatters only interpret some specific markup when a page is stored: the content is generated on-the-fly and stored in the database as ordinary Wikka content.
A couple of examples:
Short signature
:::
generates:
--
Long signature
::::
generates:
-- [2005-02-28 12:02]
Timestamp
::t::
generates:
[2005-02-28 12:02]
etc.
The code
The modifications required for this to work are quite silly. We just need to modify SavePage() in wikka.php, before the call to Query()
// one-time formatter: signature
if ($user) {
$longsignature = '-- '.$user.' [##'.date("Y-m-d H:i").'##]';
$shortsignature = '-- '.$user;
$body = preg_replace("/::::/",$longsignature,$body);
$body = preg_replace("/:::/",$shortsignature,$body);
}
// one-time formatter: timestamp
$timestamp = '[##'.date("Y-m-d H:i").'##]';
$body = preg_replace("/::t::/",$timestamp,$body);
if ($user) {
$longsignature = '-- '.$user.' [##'.date("Y-m-d H:i").'##]';
$shortsignature = '-- '.$user;
$body = preg_replace("/::::/",$longsignature,$body);
$body = preg_replace("/:::/",$shortsignature,$body);
}
// one-time formatter: timestamp
$timestamp = '[##'.date("Y-m-d H:i").'##]';
$body = preg_replace("/::t::/",$timestamp,$body);
A similar hack has to be done in the preview section of handlers/page/edit.php.
The timestamp markup is just an example, not something I would implement as such in Wikka (the format should be configurable).
Issues
As usual, what we need is a good markup (easy to remember, distinctive, expressive). If we choose to adopt :: as a tag for extensible markup, then the solution I propose here is not optimal.Your thoughts?
Related discussion
CategoryDevelopmentFormatters
Just an idea: perhaps something like ::user:: ::usertime:: and ::time:: where "user" "time" and "usertime" would/could be defined in the config (to allow it to be changed in other languages). Should get an entry in WikiEdit, though, so that you could at it without having to know the actuall names.
Also, why not make it a proper preformatter, so use $this->Format and call up a preformat.php routine. It would be really nice that " -- " was converted to — "..." to … &'s were always escaped unless part of entities and other goodies. Calling something like [[http://www.michelf.com/projects/php-smartypants/ SmartyPants]] before saving would be ideal for this and could be part of the preformatting to add typographical sharpness and a cleanly encoded page in the database, along with the user signatures.
I agree with Ian that using keywords instead of symbols is not a good idea, at least for two reasons:
- replacing keywords with symbols will surely make i18n development easier (we do not assume that Malaysian or Italian users will have to learn the English word for "user" in order to add their signature, nor that the developers will translate one day all the keywords used by the formatters)
- (not in any case, but at least in my case) writing "::user::" takes exactly the same amount of characters as writing "--DarTar", so for me it wouldn't be that interesting ;-)
@Ian,
yes I like very much the idea of a preformatter and I have already seen how other engines do this. It looks pretty easy to implement, and I think it makes sense from the point of view of both typography and semantic correctness, so IMO it's a good candidate for a future release.
Using a different symbol would als help to remind the user of the different role of this markup: interpreted *once* and formatted result saved, rather than markup that remains markup and is interpreted each time a page is shown.
- works as an afterburner, so the Wikka source code is not modified;
- requires no modification at all in the SmartyPants engine (which is important for 3rd party plugins)
http://wikka.jsnx.com/SmartyPants
Feedback welcome