On Thu, Jan 15, 2009 at 10:22 AM, Johan Sørensen
<[email protected]> wrote:
>
>
> I'd admit I was a bit lazy with the wikiwords syntax, here's what I'm
> matching against:
> WIKI_WORD = /\b[A-Z][a-z]+[A-Z]\w+\b/
> BRACKETED_WIKI_WORD = /\[\[\s*([A-Z][a-z]+([A-Z][a-z]+)?)\s*\]\]/
>
Well, first of all, the point of the brackets is to eliminate the need
for CamelCase isn't it? So actually, your bracketed regex could be
even lazier. And for CamelCase, at the very least there should be a
way to escape them so the document author can opt-out of them being
converted to links - a very valid concern when writing about code
(just consider the number of words in this email that would be
incorrectly converted to links).
The following regexs have proved rather reliable over time for the
WikiLinks extension for Python-Markdown:
WIKI_WORD = /(\\|\b)(([A-Z]+[a-z-_]+){2,})\b/
BRACKETED_WIKI_WORD = /\[\[([A-Za-z0-9_ -]+)\]\]/
For the escaping on WIKI_WORD, if the first group matches a backslash,
then simply return the contents of the second group unaltered (without
the backslash). However, if the first group matches the word-boundary,
then convert the second group into a link.
We eventually completely dropped the CamelCase syntax and only use
bracketed links. It's a lot more flexible and and doesn't surprise
authors with links in places they never expected or intended. As an
added bonus, underscores in the link are converted to spaces in the
label. So
[[Foo_Bar-42]]
becomes:
<a href=".../Foo_Bar-42">Foo Bar-42</a>
--
----
Waylan Limberg
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Gitorious" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/gitorious?hl=en
-~----------~----~----~----~------~----~------~--~---