[pmwiki-users] "Wrapping" a markup rule
Joachim Durchholz
jo at durchholz.org
Sat Apr 16 15:16:01 CDT 2005
Hi all,
just to check that I'm not doing totally whacky.
I'm currently working on improvements for eProtect.
One of the things I'd like to improve is to reuse the code from the
PmWiki core that recognises links (all that [[...]], [[...|...]], and
[[...->...]] stuff). Link recognition isn't trivial and covers several
borderline cases, and instead of recreating the expertise and experience
that went into fine-tuning the regular expressions used for the task,
I'd like to simply reuse them.
Here's how I want to do that (exemplified for the [[...->...]] markup):
1. Find the '[[->' entry in $MarkupTable.
2. Replace its 'rep' part with code that does the following:
if pattern is of the form "...-> mailto:...]]" then
return email markup (eProtect generates special HTML for that)
else
run the code originally found in the 'rep' part
end if
I.e. I'm just wrapping the 'rep' part of an existing markup rule.
I'd be happy to hear of caveats.
Things to consider:
1) this will fail if a link rule is not present for any reason (say,
somebody applied a recipe that removes link markups). One could argue
that in these cases the eProtect markup shouldn't be applied anyway,
since all it does is another layer on top of the link handling of PmWiki.
2) this assumes that the link markups all generate the replacement text
using PHP code. Currently they do, and I don't expect this to change,
but it's still a dependency on the internals of some core PmWiki
functionality.
3) when we're at it, I'm hacking away at a core data structure of
PmWiki. The approach may break if Pm ever decides to change the way
markups are done.
4) there's also a dependency on the way that the regular expressions are
built. E.g. for [[...->...]], $1 is the part between [[ and ->, and $2
the part between -> and ]]. This might change any time (e.g. when
additional subpatterns are introduced to capture more esoteric forms of
links).
5) On the plus side, this approach will make eProtect automagically
adapt to most changes in the syntax of [[...->...]].
So I ask: is this idea totally whacko, or is it the best invention since
sliced bread? I'm open to opinions from both sides ;-)
Regards,
Jo
More information about the pmwiki-users
mailing list