foo bar baz\n
|,
'unindented code markers should still work' );
$wikitext = <nothing!, '... should start new text with paragraph' );
# another buglet had the wrong tag pairs when ending a list
my $wikiexample =< I am modifying this!,
'... should use correct tags when ending lists' );
like( $htmltext, qr! Here is a paragraph. Here is another paragraph.
!,
'... should add no newline before paragraph, but at newline in paragraph ');
like( $htmltext, qr!heading
!,
'headings should be marked' );
like( $htmltext, qr!sub heading
!,
'... and numbered appropriately' );
# test overridable tags
ok( ! main->can( 'wikiformat' ), 'Module should import nothing by default' );
can_ok( 'Text::WikiFormat', 'import' );
# given an argument, export wikiformat() somehow
package Foo;
Text::WikiFormat->import('wikiformat');
::can_ok( 'Foo', 'wikiformat' );
package Bar;
Text::WikiFormat->import( as => 'wf', prefix => 'foo', tag => 'bar' );
::can_ok( 'Bar', 'wf' );
::isnt( \&wf, \&Text::WikiFormat::format,
'... and should be a wrapper around format()' );
my @args;
local *Text::WikiFormat::format;
*Text::WikiFormat::format = sub {
@args = @_;
};
wf();
::is( $args[2]{prefix}, 'foo',
'imported sub should pass through default option' );
::is( $args[1]{tag}, 'bar', '... and default tag' );
wf('text', { tag2 => 1 }, { prefix => 'baz' });
::is( $args[0], 'text', '... passing through text unharmed' );
::is( $args[1]{tag2}, 1, '... along with new tags' );
::is( $args[2]{prefix}, 'baz', '... overriding default args as needed' );
1;
Text-WikiFormat-0.79/t/bugs.t 0000444 0001750 0001750 00000005144 10641062332 016542 0 ustar chromatic chromatic #!perl
use strict;
use warnings;
use Test::More tests => 16;
use_ok( 'Text::WikiFormat' );
my $wikitext =<
test
\n", 'successful prior match should not whomp format()'); $wikitext =<<'WIKI'; Here is some example code: sub example_code { my ( $foo ) = @_; my $this = call_that( $foo ); } Isn't it nice? WIKI $htmltext = Text::WikiFormat::format($wikitext, { blocks => { code => '\t' }} ); like( $htmltext, qr!sub example_code[^<]+}\s*
!m,
'pre tags should work' );
like( $htmltext, qr!^\tmy \( \$foo \)!m, '... not removing further indents' );
$wikitext =<I download code from http://www.cpan.org/ | .
qq|or ftp://ftp.cpan.org/ and
| . "\n" .
q|email mailto:chromatic@example.com
I download code from http://www.cpan.org/ or ftp://ftp.cpan.org/ and
| . "\n" .
q|email mailto:chromatic@example.com
this is a moose:notalink
\n|, q|Doesn't pick up things that might look like links| ); $htmltext = Text::WikiFormat::format( $wikitext, {schemas => ['moose']}, { extended => 1, absolute_links => 1 } ); is( $htmltext, qq|this is a moose:notalink
\n|, q|Schema tag allows specifying what is a link| ); Text-WikiFormat-0.79/t/lists-nested.t 0000444 0001750 0001750 00000002461 10641062332 020217 0 ustar chromatic chromatic #!perl use strict; use warnings; use Test::More tests => 6; use_ok( 'Text::WikiFormat' ) or exit; my $wikitext =<my
.+text
', "
\n", '', "\n" ],
line => [ '', "\n", '', "
\n", '', ",
C, and C. The parser usually finds these by indentation,
either one or more tabs or four or more whitespace characters. (This does not
include newlines, however.) Any line that does not fall in any of these three
categories is a C.
Code, unordered, and ordered blocks do not I indentation, but the
parser uses it to control nesting in lists. Be careful. To mark a block as
requiring indentation, use the C tag, which contains a reference to a
hash:
my $html = format($text, {
indented => { map { $_ => 1 } qw( ordered unordered code )}
});
Block entries in the tag hashes must contain array references. The first two
items are the tags used at the start and end of the block. The last items
contain the tags used at the start and end of each line. Where there needs to
be more processing of individual lines, use a subref as the third item. This
is how the module numbers ordered lines in HTML lists:
my $html = format($text, { ordered => [ '', "
\n",
sub { qq|$_[0] \n| } ] });
The first argument to these subrefs is the post-processed text of the line
itself. (Processing removes the indentation and tokens used to mark this as a
list and checks the rest of the line for other line formattings.) The second
argument is the indentation level. The subsequent arguments are captured
variables in the regular expression used to find this list type. The regexp
for ordered lists is:
qr/^([\dA-Za-z]+)\.\s*/;
The module processes indentation first, if applicable, and stores the
indentation level (the length of the indentation removed). The line must
contain one or more alphanumeric character followed by a single period and
optional whitespace to be an ordered list item. The module saves the contents
of this last group, the value of the list item, and passes it to the subref as
the third argument.
Lists automatically start and end as necessary.
Because of the indentation issue, there is a specific blocks processing in a
specific order. The C tag governs this order. It contains a
reference to an array of the names of the appropriate blocks to process. If
you add a block type, be sure to add an entry for it in C:
my $html = format($text, {
escaped => [ '', '', '', '' ],
blocks => {
invisible => qr!^--(.*?)--$!,
},
blockorder =>
[qw( header line ordered unordered code paragraph invisible )],
});
=head3 Finding blocks
Text::WikiFormat uses regular expressions to find blocks. These are in the
C<%tags> hash under the C key. To change the regular expression to
find code block items, use:
my $html = format($wikitext, {
blocks => {
code => qr/^:\s+/,
},
indented => {
code => 1,
},
);
This will require indentation and a colon to mark code lines. A potential
shortcut is to use the C tag to match or to change the indentation
marker.
B: if you want to mark a block type as non-indented, you B use an
empty regex such as C . Use a mostly-empty, always-true regex such as
C instead.
=head3 Finding Blocks in the Correct Order
As intrepid bug reporter Tom Hukins pointed out in CPAN RT bug #671, the order
in which Text::WikiFormat searches for blocks varies by platform and version of
Perl. Because some block-finding regular expressions are more specific than
others, what you intend to be one type of block may turn into a different list
type.
If you're adding new block types, be aware of this. The C entry in
C<%tags> exists to force Text::WikiFormat to apply its regexes from most
specific to least specific. It contains an array reference. By default, it
looks for ordered lists first, unordered lists second, and code references at
the end.
=head1 AUTHOR
chromatic, C, with much input from the Jellybean team
(including Jonathan Paulett). Kate L Pugh has also provided several patches,
many failing tests, and is usually the driving force behind new features and
releases. If you think this module is worth buying me a beer, she deserves at
least half of it.
Alex Vandiver added a nice patch and tests for extended links.
Tony Bowden, Tom Hukins, and Andy H. all suggested useful features that are now
implemented.
Sam Vilain, Chris Winters, Paul Schmidt, and Art Henry have all found and
reported silly bugs.
Blame me for the implementation.
=head1 BUGS
The link checker in C may fail to detect existing links that do
not follow HTML, XML, or SGML style. They may die with some SGML styles too.
I.
=head1 TODO
=over 4
=item * Find a nicer way to mark list as having unformatted lines
=item * Optimize C to work on a list of lines
=item * Handle nested C and C markings better
=back
=head1 OTHER MODULES
Brian "Ingy" Ingerson's CGI::Kwiki has a fairly nice parser.
John McNamara's Pod::Simple::Wiki looks like a good project.
Matt Sergeant keeps threatening to write a nice SAX-throwing Wiki formatter.
=head1 COPYRIGHT
Copyright (c) 2002 - 2006, chromatic. All rights reserved. This module is
distributed under the same terms as Perl itself.
Text-WikiFormat-0.79/lib/Text/WikiFormat/ 0000755 0001750 0001750 00000000000 10641062332 020716 5 ustar chromatic chromatic Text-WikiFormat-0.79/lib/Text/WikiFormat/Blocks.pm 0000444 0001750 0001750 00000012366 10641062332 022477 0 ustar chromatic chromatic package Text::WikiFormat::Blocks;
use strict;
use warnings;
sub import
{
my $caller = caller();
no strict 'refs';
*{ $caller . '::new_block' } = sub
{
my $type = shift;
my $class = "Text::WikiFormat::Block::$type";
my $ctor;
unless ($ctor = $class->can( 'new' ))
{
@{ $class . '::ISA' } = ( 'Text::WikiFormat::Block' );
$ctor = $class->can( 'new' );
}
return $class->new( type => $type, @_ );
};
}
package Text::WikiFormat::Block;
use Scalar::Util qw( blessed reftype );
sub new
{
my ($class, %args) = @_;
$args{text} = $class->arg_to_ref( delete $args{text} || '' );
$args{args} = [ $class->arg_to_ref( delete $args{args} || [] ) ];
bless \%args, $class;
}
sub arg_to_ref
{
my ($class, $value) = @_;
return $value if ( reftype( $value ) || '' ) eq 'ARRAY';
return [ $value ];
}
sub shift_args
{
my $self = shift;
my $args = shift @{ $self->{args} };
return wantarray ? @$args : $args;
}
sub all_args
{
my $args = $_[0]{args};
return wantarray ? @$args : $args;
}
sub text
{
my $text = $_[0]{text};
return wantarray ? @$text : $text;
}
sub add_text
{
my $self = shift;
push @{ $self->{text} }, @_;
}
sub formatted_text
{
my $self = shift;
return map
{
blessed( $_ ) ? $_ : $self->formatter( $_ )
} $self->text();
}
sub formatter
{
my ($self, $line) = @_;
Text::WikiFormat::format_line( $line, $self->tags(), $self->opts() );
}
sub add_args
{
my $self = shift;
push @{ $self->{args} }, @_;
}
{
no strict 'refs';
for my $attribute (qw( level opts tags type ))
{
*{ $attribute } = sub { $_[0]{$attribute} };
}
}
sub merge
{
my ($self, $next_block) = @_;
return $next_block unless $self->type() eq $next_block->type();
return $next_block unless $self->level() == $next_block->level();
$self->add_text( $next_block->text() );
$self->add_args( $next_block->all_args() );
return;
}
sub nests
{
my $self = shift;
return exists $self->{tags}{nests}{ $self->type() };
}
sub nest
{
my ($self, $next_block) = @_;
return unless $next_block = $self->merge( $next_block );
return $next_block unless $self->nests() and $next_block->nests();
return $next_block unless $self->level() < $next_block->level();
# if there's a nested block at the end, maybe it can nest too
my $last_item = ( $self->text() )[-1];
return $last_item->nest( $next_block ) if blessed( $last_item );
$self->add_text( $next_block );
return;
}
package Text::WikiFormat::Block::code;
use base 'Text::WikiFormat::Block';
sub formatter { $_[1] }
package Text::WikiFormat::Blocks;
1;
__END__
=head1 NAME
Text::WikiFormat::Blocks - blocktypes for Text::WikiFormat
=head1 SYNOPSIS
None. Use L as the public interface, unless you want to
create your own block type.
=head1 DESCRIPTION
This module merely creates subclasses of Text::WikiFormat::Block, which is the
interesting code. A block is a collection of related lines, such as a code
block (text to display verbatim in a monospaced font), a header, an unordered
list, an ordered list, and a paragraph (text to display in a proportional
font).
Every block extends C.
=head1 METHODS
The following methods exist:
=over 4
=item * C
Creates and returns a new block. The valid arguments are:
=over 4
=item * C
The text of the line found in the block.
=item * C
The arguments captured by the block-identifying regular expression.
=item * C
The level of indentation for the block (usually only useful for list blocks).
=item * C
The tags in effect for the current type of wiki formatting.
=item * C
The options in effect for the current type of wiki formatting.
=back
Use the accessors of the same names to retrieve the values of the attributes.
=item * C
Adds a list of lines of text to the current text for the block. This is very
useful when you encounter a block and want to merge it with the previous block
of the same type
=item * C
Adds further arguments to the block; useful when merging blocks.
=item * C
Returns text formatted appropriately for this block. Blocks don't have to have
formatters, but they may.
=item * C
Formats the C<$line> using C. You can add
your own formatter here; this is worth overriding.
=item * C
Merges the current block with C<$next_block> (the next block encountered) if
they're of the same type and are at the same level. This adds the text and
args of C<$next_block> to the current block. It's your responsibility to
remove C<$next_block> from whatever your code iterates over.
=item * C
Returns true if this block should nest (as in lists and unordered lists) for
the active wiki formatting.
=item * C
Nests C<$next_block> under this block if the both nest and if C<$next_block>
has a level greater than the current block. This actually adds C<$next_block>
as a text item within the current block. Beware.
=back
=head1 AUTHOR
chromatic, C<< chromatic at wgz dot org >>
=head1 BUGS
No known bugs.
=head1 COPYRIGHT
Copyright (c) 2006, chromatic. Some rights reserved.
This module is free software; you can use, redistribute, and modify it under
the same terms as Perl 5.8.x.
Text-WikiFormat-0.79/META.yml 0000444 0001750 0001750 00000002023 10641062332 016414 0 ustar chromatic chromatic ---
name: Text-WikiFormat
version: 0.79
author:
- |-
chromatic, C, with much input from the Jellybean team
(including Jonathan Paulett). Kate L Pugh has also provided several patches,
many failing tests, and is usually the driving force behind new features and
releases. If you think this module is worth buying me a beer, she deserves at
least half of it.
abstract: module for translating Wiki formatted text into other formats
license: perl
resources:
license: http://dev.perl.org/licenses/
requires:
Scalar::Util: 1.14
URI::Escape: ''
build_requires:
Test::More: 0.30
provides:
Text::WikiFormat:
file: lib/Text/WikiFormat.pm
version: 0.79
Text::WikiFormat::Block:
file: lib/Text/WikiFormat/Blocks.pm
Text::WikiFormat::Block::code:
file: lib/Text/WikiFormat/Blocks.pm
Text::WikiFormat::Blocks:
file: lib/Text/WikiFormat/Blocks.pm
generated_by: Module::Build version 0.2808
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
Text-WikiFormat-0.79/ARTISTIC 0000444 0001750 0001750 00000014463 10641062332 016323 0 ustar chromatic chromatic The "Artistic License"
Preamble
The intent of this document is to state the conditions under which a
Package may be copied, such that the Copyright Holder maintains some
semblance of artistic control over the development of the package,
while giving the users of the package the right to use and distribute
the Package in a more-or-less customary fashion, plus the right to
make reasonable modifications.
Definitions
"Package" refers to the collection of files distributed by the
Copyright Holder, and derivatives of that collection of files
created through textual modification.
"Standard Version" refers to such a Package if it has not been
modified, or has been modified in accordance with the wishes of the
Copyright Holder as specified below.
"Copyright Holder" is whoever is named in the copyright or
copyrights for the package.
"You" is you, if you're thinking about copying or distributing this
Package.
"Reasonable copying fee" is whatever you can justify on the basis
of media cost, duplication charges, time of people involved, and so
on. (You will not be required to justify it to the Copyright
Holder, but only to the computing community at large as a market
that must bear the fee.)
"Freely Available" means that no fee is charged for the item
itself, though there may be fees involved in handling the item. It
also means that recipients of the item may redistribute it under
the same conditions they received it.
1. You may make and give away verbatim copies of the source form of
the Standard Version of this Package without restriction, provided
that you duplicate all of the original copyright notices and
associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications
derived from the Public Domain or from the Copyright Holder. A
Package modified in such a way shall still be considered the
Standard Version.
3. You may otherwise modify your copy of this Package in any way,
provided that you insert a prominent notice in each changed file
stating how and when you changed that file, and provided that you
do at least ONE of the following:
a. place your modifications in the Public Domain or otherwise make
them Freely Available, such as by posting said modifications to
Usenet or an equivalent medium, or placing the modifications on a
major archive site such as uunet.uu.net, or by allowing the
Copyright Holder to include your modifications in the Standard
Version of the Package.
b. use the modified Package only within your corporation or
organization.
c. rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and
provide a separate manual page for each non-standard executable
that clearly documents how it differs from the Standard Version.
d. make other distribution arrangements with the Copyright Holder.
You may distribute the programs of this Package in object code or
executable form, provided that you do at least ONE of the following:
a. distribute a Standard Version of the executables and library
files, together with instructions (in the manual page or
equivalent) on where to get the Standard Version.
b. accompany the distribution with the machine-readable source of the
Package with your modifications.
c. give non-standard executables non-standard names, and clearly
document the differences in manual pages (or equivalent), together
with instructions on where to get the Standard Version.
d. make other distribution arrangements with the Copyright Holder.
You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this
Package. You may not charge a fee for this Package itself. However,
you may distribute this Package in aggregate with other (possibly
commercial) programs as part of a larger (possibly commercial)
software distribution provided that you do not advertise this Package
as a product of your own. You may embed this Package's interpreter
within an executable of yours (by linking); this shall be construed as
a mere form of aggregation, provided that the complete Standard
Version of the interpreter is so embedded.
The scripts and library files supplied as input to or produced as
output from the programs of this Package do not automatically fall
under the copyright of this Package, but belong to whomever generated
them, and may be sold commercially, and may be aggregated with this
Package. If such scripts or library files are aggregated with this
Package via the so-called "undump" or "unexec" methods of producing a
binary executable image, then distribution of such an image shall
neither be construed as a distribution of this Package nor shall it
fall under the restrictions of Paragraphs 3 and 4, provided that you
do not represent such an executable image as a Standard Version of
this Package.
C subroutines (or comparably compiled subroutines in other
languages) supplied by you and linked into this Package in order to
emulate subroutines and variables of the language defined by this
Package shall not be considered part of this Package, but are the
equivalent of input as in Paragraph 6, provided these subroutines do
not change the language in any way that would cause it to fail the
regression tests for the language.
Aggregation of this Package with a commercial distribution is always
permitted provided that the use of this Package is embedded; that is,
when no overt attempt is made to make this Package's interfaces
visible to the end user of the commercial distribution. Such use shall
not be construed as a distribution of this Package.
The name of the Copyright Holder may not be used to endorse or
promote products derived from this software without specific prior
written permission.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
Text-WikiFormat-0.79/README 0000444 0001750 0001750 00000000577 10641062332 016037 0 ustar chromatic chromatic Text::WikiFormat converts text in a simple Wiki markup language to whatever
your little heart desires, provided you can describe it accurately in a
semi-regular tag language.
This program is Free Software, provided without warranty or implied
merchantability, but available under the same terms as Perl itself. What a
deal! It's copyrighted and copylefted 2002 - 2006, chromatic.
Text-WikiFormat-0.79/Makefile.PL 0000444 0001750 0001750 00000001007 10641062332 017116 0 ustar chromatic chromatic # Note: this file was auto-generated by Module::Build::Compat version 0.03
use ExtUtils::MakeMaker;
WriteMakefile
(
'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'NAME' => 'Text::WikiFormat',
'EXE_FILES' => [],
'VERSION_FROM' => 'lib/Text/WikiFormat.pm',
'PREREQ_PM' => {
'Test::More' => '0.30',
'Scalar::Util' => '1.14',
'URI::Escape' => ''
}
)
;
Text-WikiFormat-0.79/Build.PL 0000555 0001750 0001750 00000001623 10641062332 016447 0 ustar chromatic chromatic #! perl
use Module::Build;
my $class = Module::Build->subclass(
class => 'Module::Build::FilterTests',
code => <<'END_HERE',
use File::Glob;
use File::Spec::Functions;
sub ACTION_disttest
{
my $self = shift;
local $ENV{PERL_RUN_ALL_TESTS} = 1;
$self->SUPER::ACTION_disttest( @_ );
}
sub find_test_files
{
my $self = shift;
my $tests = $self->SUPER::find_test_files( @_ );
return $tests unless $ENV{PERL_RUN_ALL_TESTS};
my $test_pattern = catfile(qw( t developer *.t ) );
push @$tests, File::Glob::bsd_glob( $test_pattern );
return $tests;
}
END_HERE
);
my $build = $class->new(
license => 'perl',
module_name => 'Text::WikiFormat',
requires =>
{
'URI::Escape' => '',
'Scalar::Util' => '1.14',
},
build_requires =>
{
'Test::More' => '0.30',
},
create_makefile_pl => 'traditional',
sign => '1',
);
$build->create_build_script();