MojoMojo::Formatter::Wiki − Handle interpage linking.
This formatter handles intra-Wiki links specified between double square brackets or parentheses: [[wiki link]] or ((another wiki link)). It will also indicate missing links with a question mark and a link to the edit page. Links can be implicit (like the two above), where the path is derived from the link text by replacing spaces with underscores (<a href="wiki_link">wiki link</a>), or explicit, where the path is specified before a ’|’ sign:
[[/explicit/path|Link text goes here]]
Note that external links have a different syntax: [Link text](http://foo.com).
Format order can be 1−99. The Wiki formatter runs on 10.
Replace <pre ... with a placeholder
Put pre and lang back into place.
Calls the formatter. Takes a ref to the content as well as the context object.
format_link <c> <wikilink> <base> [<link_text>]
Format a wikilink as an HTML hyperlink with the given link_text. If the wikilink doesn’t exist, it will be rendered as a hyperlink to an .edit page ready to be created.
Since there is no difference in syntax between new and existing links, some abiguities my occur when it comes to characters that are invalid in URLs. For example,
* [[say " NO" to #8]] should be rendered as "<a href="say_%22NO%22_to_%238">say "NO" to #8</a>" * [[100% match]] should be rendered as "<a href="100%25_match>100% match</a>", URL-escaping the ’%’ * but what about a user pasting an existing link, "[[say_%22NO%22_to_%238]]"? We shouldn’t URL-escape the ’%’ or ’#’ here. * for links with explicit link text, we should definitiely not URL-escape the link: "[[say_%22NO%22_to_%238|say "NO" to #8]]"
This is complicated by the fact that ’#’ can delimit the start of the anchor portion of a link.
* "[[Mambo #5]]" − URL-escape ’#’ => Mambo_%235 * "[[Mambo#origins]]" − do not URL-escape * "[[existing/link#Introduction|See the Introduction]]" − definitely do not URL-escape
Since escaping is somewhat magic and therefore potentially counter-intuitive, we will: * only URL-escape ’#’ if it follows a whitespace directly * always URL-escape ’%’ unless it is followed by two uppercase hex digits * always escape other characters that are invalid in URLs
Replace "_" with spaces and unescape URL-encoded characters
find_links <content> <page>
Find wiki links in content.
Return a listref of linked (existing) and wanted pages.
Marcus Ramberg <mramberg AT cpan DOT org>
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.