NAME
Text::KwikiFormatish - (OLD) convert Kwikitext into XML-compliant HTML
SYNOPSIS
# use Text::KwikiFormat instead
use Text::KwikiFormatish;
my $xml = Text::KwikiFormatish::format($text);
DESCRIPTION
CGI::Kwiki includes a formatter (CGI::Kwiki::Formatter) for converting Kwikitext (a nice form of wikitext) to HTML. Unfortunately, it isn't easy to use the formatter outside the CGI::Kwiki environment. Additionally, the HTML produced by the formatter isn't XHTML-1 compliant. This module aims to fix both of these issues and provide an interface similar to Text::WikiFormat.
Essentially, this module is the code from Brian Ingerson's CGI::Kwiki::Formatter with a format
subroutine, code relating to slides removed, tweaked subroutinesa, and more.
Since the wikitext spec for input wikitext for this module differs a little from the default Kwiki formatter, I thought it best to call it "Formatish" instead of *the* Kwiki Format.
format()
format()
takes one or two arguments, with the first always being the wikitext to translate. The second is a hash of options, but currently the only option supported is prefix
in case you want to prefix wiki links with sommething. For example,
my $xml = Text::KwikiFormatish::format(
$text,
prefix => '/wiki/',
);
Subclassing the Formatter
CGI::Kwiki::Formatter was designed to be subclassable so that the formatting engine could be easily customized. Information on how the Kwiki formatter works can be found at HowKwikiFormatterWorks.
For example, say you wanted to override the markup for strong (bold) text. You decide that it would make much more sense to write strong text as HEYthis is bold textHEY
. You would subclass Text::KwikiFormatish and use it like so:
package My::Formatter;
use base 'Text::KwikiFormatish';
# you need this
sub format { __PACKAGE__->new->process(@_) }
# I simply copied this from Text/KwikiFormatish.pm and tweaked it
sub bold {
my ($self, $text) = @_;
$text =~ s#(?<![$WORD])HEY(\S.*?\S|\S)HEY(?![$WORD])#<strong>$1</strong>#g;
return $text;
}
package main;
my $data = join( '', <> );
print My::Formatter::format( $data );
NOTE: I dug myself into a hole by making this a drop-in replacement for Text::WikiFormat, hence the format
subroutine.
process_order()
process_order()
returns a list of the formatting rules that will be applied when format
is called for this object. If called with a set of formatting rules (names of class methods), that set of formatting rules will supercede the default set.
Differences from the Kwiki Formatter
The output of the formatter is XML-compliant.
Extra equal signs at the end of headings will be removed from the output for compatibility with other wikitext formats.
Italicized text is marked up by two slashes instead of one. This is to prevent weirdness when writing filesystem paths in Kwikitext -- e.g., the text "Check /etc or /var or /usr/" will have unexpected results when formatted in a regular Kwiki.
Horizontal rules, marked by four or more hyphens, may be followed by spaces.
Processing order of text segments has been changed (tables are processed last)
Bold text is marked up as
<strong>
instead of<b>
"Inline" is marked up as
<code>
instead of<tt>
mdashes (really long hyphens) are created with wikitext
like---this
Tables and code sections are not indented with
<blockquote>
tagsComments do not have to have a space immediately following the hash
Patch to named_link code
All code pertaining to slides or Kwiki access control is removed, as neither are within the scope of this module
Plugins
I've included two plugins, img
and icon
, to do basic image support besides the standard operation of including an image when the URL ends with a common image extension.
EXAMPLES
Here's some kwiki text. (Compare with KwikiFormattingRules.)
= Level 1 Header
== Level 2 with optional trailing equals ==
Kwikitext provides a bit more flexibility than regular wikitext.
All HTML code is <escaped>. Horizontal rules are four or more hyphens:
----
While you can add an mdash---like this.
##
## you can add comments in the kwikitext which appear as XML comments
##
== Links
=== Itemized Lists
* Fruit
** Oranges
** Apples
* Eggs
* Salad
=== Enumerated Lists
##
## below are zero's, not "oh's"
##
0 One
0 Two
0 Three
* Comments in the wikitext
* Easier:
** Bold/strong
** Italic/emphasized
== More Markup
*strong or bold text*
//emphasized or italic text//
indented text is verbatim (good for code)
== Links
WikiLink
!NotAWikiLink
http://www.kwiki.org/
[Kwiki named link http://www.kwiki.org/]
== Images
http://search.cpan.org/s/img/cpan_banner.png
== KwikiFormatish plugins
This inserts an image with the CSS class of "icon" -- good for inserting a right-aligned image for text to wrap around.
[&icon /images/logo.gif]
The following inserts an image with an optional caption:
[&img /images/graph.gif Last Month's Earnings]
AUTHOR
Maintained by Ian Langworth - ian[aught]cpan.org
Based on CGI::Kwiki::Formatter by Brian Ingerson.
Thanks to Jesse Vincent for the process_order
patch, related documentation and testing.
Additional thanks to Mike Burns and Ari Pollak for additional testing.
SEE ALSO
CGI::Kwiki, CGI::Kwiki::Formatter, Text::WikiFormat
LICENSE
This is free software. You may use it and redistribute it under the same terms as perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 653:
You forgot a '=back' before '=head2'
- Around line 657:
=back without =over