So, I answer a lot of questions here - can I abuse the relationship with you readers and ask for your help? I finally have some folks using Canvas, my ColdFusion Wiki, and because of this, bugs are cropping up.
The main bug involves the fact that some Wiki commands, like +...+ for bold, intefere with other commands, like the URL generator. I use [[url]] to create URLs, but if you do [[http://www.cnn.com/foo_mon]] then the parser will find the _ in the URL. If another _ exists later on, then a match is found.
What I need is to find matches that are not inside HTML. Apparently this is possible using negative lookbehind, which ColdFusion doesn't support.
Does anyone have any bright ideas? I've noticed other Wikis seem to get around this by using tokens that can't appear in URLs.
The other problem is that you can't use + and _ in normal text either. So this "5+5 = 2" would be a problem. I'm thinking for that I may just ask people to escape, i.e., use 5++5=2. That seem ok to folks?
Archived Comments
Ray: This is what I use to handle _italics_:
^\_([^\_]+)\_
...and...
([[:space:]>])\_([^\_]+)\_
Basically, the first will only match stuff that's at the beginning of a line, and the second will only match stuff with a space in front of it. Put them together, and you've got 90% of situations covered.
Ray - I think the way I'd handle this (and it might not be what you want to do) is to implement FCKeditor instead of the formatting syntax. You could then limit the number of formatting functions avaliable and add one custom button to create new wiki terms.
Oh, and not to be a jerk, but I really dislike the "wiki terms" functionality as it currently exists. If I have something that's more than one word I don't want to have to squish it together into a camel-case word just to make it a link.
My solution though was to simply change how that render behavior functions so that I just wrapped things in a % sign.
I also added the ability to wrap a chunk of text in a [code] block and have it format as code. It's not elegant, but it works.
Doug, you don't need to use WikiTerms to make links. WikiTerms is just one way. You can also do internal links using: [[Foo|Label]].
Roger, I'm having some luck with this idea: To use an _, you escape it by doubling it. My regex first replaces __ with chr(1), then does the normal _..._ replacement, than replaces chr(1) with _. Seems ok I think.
Java 1.4 RegExp libraries support lookbehind, you can bypass CF's RegExp and leverage Java instead.
You could use this UDF:
http://www.cfmentor.com/cod...
Or give this CFC a try:
http://www.massimocorner.co...
Massimo
Raymond - Could you loop through and replace the bad characters with their ASCII equivalents (replace _ with chr(95)) or would the chr(95) be evaluated anyways and throw it off?
Massimo, I'll give it a try - but first I want to see if my users mind the 'escape' route. Ie, they can use _ or + but must escape them first.
Why not switch to some other common markup like BBCode, wherein you would be able to use this style of formatting:
[B]This is bold[/B]
[I]This is italic[/I]
Brackets instead of angle-brackets like in html. This is how most of the other forums type software works (IPB, PHPBB, etc.). *Something* is going to have to be escaped to make this work - I would personally rather escape my formatting codes rather than the main text of my post. It's far more intuitive that way.
I see your point - but I don't think this will be too difficult. Let me see how the public reacts though. _ isn't used much in normal text.
I really like Roland's suggestion. Consider this a positive reaction.
Massimo, I didn't realize your solution was so nicely packaged. I'm having a bit of trouble with it - do you mind if I ping you directly via email?
Ok, guys, I gave up. [b] and [i] it is. Doug, you want to test this real quick?
Sure, kick it off to me.
Sure Ray, feel free to contact me directely whenever you want.
Massimo
Thanks Massimo. I ended up using the [b] format anyway. Your regex libraries did work - I just had issues with the regex I was using.
The [b] format sounds like a wise choice.
Portability of RegExp's patterns across different engines can be somewhat tricky.
Java's RegExp libraries are very powerful and offer a few interesting features not available in ColdFusion, but porting non trivial patterns may require some efforts.