Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Challenge: Transforming markupsby LanX (Saint) |
on Dec 06, 2013 at 21:22 UTC ( [id://1066059]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi I need to transform or disable different (non-recursive!) markup-syntax-elements, in this case org-mode to kwiki. Now links which are freely included in text are tricky... for instance http://www.gmx.de or CamelCaseLink are valid links for kwiki ... ... and [[http://gmx.de][BlubBlub]] is a named link in org-mode. As you can see are named-links allowed to include matches for http:://links or CamelCase words which mustn't be processed again. And links can occasionally include CamelCase words. One approach is to OR the regexes with priority to the more complex ones, such that their matches are only processed once: s/ ($named|$http|$camel) / tranform() /gxe Now in the substitution part it's tricky to know which regex matched, thats why I use named captures. The following code demonstrates what I'm doing! (please note that for simplicity of the example my only transformation is to return the name of the match.) I have the impression to reinvent the wheel and fiddling with %- doesn't seem stable... So please show me easier approaches... :)
OUTPUT:
Cheers Rolf ( addicted to the Perl Programming Language)
Back to
Seekers of Perl Wisdom
|
|