[pmwiki-users] "Save & Edit" and "Preview" with custom markup
DaveG
pmwiki at solidgone.com
Mon Jan 2 21:16:30 CST 2006
Not sure if this is a bug or an error in my markup.
I have defined a markup and an $EditFunction to replace "Tags: a,b,c"
with "Cats: [[!a]],[[!b]],[[!c]]" when Saving, and to do the reverse
when Editing.
However, when using "Preview" or using "Save & Edit" the preview looks
fine, but the edit box now contains the translated markup ("Cats...")
rather than the untranslated ("Tags"). It seems that either the reverse
translation does not occur, or that the translation should not be shown
in the edit box.
~ ~ Dave
Ref: http://www.mr2wiki.com/pmwiki/index.php?n=Main.WikiSandbox
Here's the code I use:
#----
$Categories='';
Markup('^Tags:', 'directives', '/^Cats?:\s?(.*)/ie',
'PZZ(\$GLOBALS["Categories"]="Tags: $1")');
function TagsToCategories($tags) {
$categories = preg_split('/, */', $tags);
sort($categories);
if (count($categories)!=0) $tags = '[[!'.implode(']], [[!',
$categories).']]';
return 'Cats:'.$tags;
}
function CategoriesToTags($tags) {
return 'Tags:'.preg_replace('/\[\[!([\w]+)]]/', '$1', $tags);
}
function MyConvertTags($pagename, &$page, &$new) {
$x=$new['text'];
$new['text'] = preg_replace('/^Tags?: *([\w, ]+)/ie',
"TagsToCategories('$1')", $new['text']);
if ($x==$new['text'])
$new['text'] = preg_replace('/^Cats?: *([\[\[!\w\]\],
]+)/ie',"CategoriesToTags('$1')", $new['text']);
}
array_unshift($EditFunctions, 'MyConvertTags');
#----
More information about the pmwiki-users
mailing list