, dialect => 'Markdown', wiki_uri => 'http://www.test.com/wiki/' );
close DATA;
__DATA__
unordered list
__H__
__W__
* one
* two
* three
__NEXT__
ordered list
__H__
- one
- two
- three
__W__
1. one
2. two
3. three
__NEXT__
blockquote
__H__
text
__W__
> text
__NEXT__
nested blockquote
__H__
texttext2
__W__
> text
>
> > text2
__NEXT__
nested blockquote cont'd
__H__
This is the first level of quoting.
This is nested blockquote.
Back to the first level.
__W__
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
__NEXT__
h1
__H__
text
__W__
# text
__NEXT__
bold
__H__
bold text
__W__
**bold text**
__NEXT__
italics
__H__
text
__W__
_text_
__NEXT__
strong
__H__
text
__W__
**text**
__NEXT__
em
__H__
text
__W__
_text_
__NEXT__
inline link ::link_style('inline')
__H__
It's called LTP.
__W__
It's called [LTP](http://en.wikipedia.org/wiki/Long-term_potentiation Long-term potentiation).
__NEXT__
reference link ::link_style('reference')
__H__
It's called LTP.
__W__
It's called [LTP][1].
[1]: http://en.wikipedia.org/wiki/Long-term_potentiation "Long-term potentiation"
__NEXT__
reference link no title ::link_style('inline')
__H__
This link has no title attribute.
__W__
[This link](http://example.net/) has no title attribute.
__NEXT__
multi-paragraphs with reference links ::link_style('reference')
__H__
This is a paragraph with a link to Google.
There's also a link to some other stuff, like Digg
and Wikipedia.
Here's another paragraph.
This is fun stuff:
__W__
This is a paragraph with a link to [Google][1]. There's also a link to some other stuff, like [Digg][2] and [Wikipedia][3].
Here's another paragraph.
This is fun stuff:
* [Google Video is the best!][4]
* [Example.org is a close second][5]
[1]: http://google.com
[2]: http://digg.com
[3]: http://wikipedia.org
[4]: http://video.google.com "Google Video"
[5]: http://www.example.org "Examples"
__NEXT__
code
__H__
printf()
__W__
`printf()`
__NEXT__
inline image ::image_style('inline')
__H__
__W__

__NEXT__
reference image ::image_style('reference')
__H__
__W__
![Delete][1]
[1]: http://example.com/delete.png "Click to delete"
__NEXT__
mixed inline images and links ::image_style('inline') ::link_style('inline')
__H__
Link goes Here.
Image goes below:

__W__
Link goes [Here](http://example.com Link to example.com). Image goes below:

__NEXT__
mixed reference images and links ::image_style('reference') ::link_style('reference')
__H__
This is a paragraph with a link to Google. There's also a link to some other stuff, like Digg and Wikipedia. 
__W__
This is a paragraph with a link to [Google][1]. There's also a link to some other stuff, like [Digg][2] and [Wikipedia][3]. ![Delete][4]
[1]: http://google.com
[2]: http://digg.com
[3]: http://wikipedia.org
[4]: http://example.com/delete.png "Click to delete"
__NEXT__
fallback to tag if image has dimensions ::image_tag_fallback(1)
__H__
__W__
__NEXT__
no fallback ::image_tag_fallback(0) ::image_style('inline')
__H__
__W__

__NEXT__
automatic links
__H__
http://example.com
__W__
__NEXT__
escapes
__H__
a backslash \
a weird combo 
* [Philosophy](#philosophy)
* [Inline HTML](#html)
__NEXT__
table
__H__
My favorite animals
Animal |
Region |
Physical traits |
Food |
Pacman frog |
Gran Chaco (Argentina) |
Half mouth, half stomach (quite literally!) |
Crickets, fish, etc. |
__W__
My favorite animals
Animal |
Region |
Physical traits |
Food |
Pacman frog |
Gran Chaco (Argentina) |
Half mouth, half stomach (quite literally!) |
Crickets, fish, etc. |
__NEXT__
setext header ::header_style('setext')
__H__
header1
Fun stuff here.
header2
More fun stuff!
__W__
header1
=======
Fun stuff here.
header2
-------
More fun stuff!
HTML-WikiConverter-Markdown-0.02/META.yml 0100644 0004734 0023422 00000001015 10460003242 016766 0 ustar diberri hoc # http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: HTML-WikiConverter-Markdown
version: 0.02
version_from: lib/HTML/WikiConverter/Markdown.pm
installdirs: site
requires:
HTML::Tagset: 0
HTML::WikiConverter: 0.6
Params::Validate: 0
Test::More: 0
URI: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
HTML-WikiConverter-Markdown-0.02/lib/ 0040755 0004734 0023422 00000000000 10460003242 016271 5 ustar diberri hoc HTML-WikiConverter-Markdown-0.02/lib/HTML/ 0040755 0004734 0023422 00000000000 10460003242 017035 5 ustar diberri hoc HTML-WikiConverter-Markdown-0.02/lib/HTML/WikiConverter/ 0040755 0004734 0023422 00000000000 10460003242 021630 5 ustar diberri hoc HTML-WikiConverter-Markdown-0.02/lib/HTML/WikiConverter/Markdown.pm 0100644 0004734 0023422 00000024743 10460003133 023756 0 ustar diberri hoc package HTML::WikiConverter::Markdown;
use warnings;
use strict;
use base 'HTML::WikiConverter';
our $VERSION = '0.02';
use Params::Validate ':types';
use HTML::Tagset;
use URI;
=head1 NAME
HTML::WikiConverter::Markdown - Convert HTML to Markdown markup
=head1 SYNOPSIS
use HTML::WikiConverter;
my $wc = new HTML::WikiConverter( dialect => 'Markdown' );
print $wc->html2wiki( $html );
=head1 DESCRIPTION
This module contains rules for converting HTML into Markdown markup.
You should not use this module directly; HTML::WikiConverter is the
entry point for html->wiki conversion (eg, see synopsis above). See
L for additional usage details.
=head1 ATTRIBUTES
In addition to the regular set of attributes recognized by the
L constructor, this dialect also accepts the
following attributes that can be passed into the C
constructor. See L for usage details.
=head2 header_style
Possible values: C<'setext'>, C<'atx'>. Determines how headers
C-C will be formatted. See
L for more
information. Default is C<'atx'>.
=head2 link_style
Possible values: C<'inline'>, C<'reference'>. See
L for more
information. Default is C<'reference'>.
=head2 force_inline_anchor_links
Possible values: C<0>, C<1>. If enabled, links to anchors within the
same page (eg, C<#some-anchor>) will always produce inline Markdown
links, even under reference link style. This might be useful for
building tables of contents. Default is C<0>.
=head2 image_style
Possible values: C<'inline'>, C<'reference'>. See
L for more
information. Default is C<'reference'>.
=head2 image_tag_fallback
Possible values: C<0>, C<1>. Markdown's image markup does not
support image dimensions. If C is enabled, image
tags containing dimensional information (ie, width or height) will not
be converted into Markdown markup. Rather, they will be roughly
preserved in their HTML form. Default is C<1>.
=head2 unordered_list_style
Possible values: C<'asterisk'>, C<'plus'>, C<'dash'>. See
L for more
information. Default is C<'asterisk'>.
=head2 ordered_list_style
Possible values: C<'sequential'>, C<'one-dot'>. Markdown supports two
different markups for ordered lists. Sequential style gives each list
element its own ordinal number (ie, C<'1.'>, C<'2.'>, C<'3.'>,
etc.). One-dot style gives each list element the same ordinal number
(ie, C<'1.'>). See
L for more
information. Default is C<'sequential'>.
=cut
sub attributes { {
header_style => { default => 'atx', type => SCALAR },
link_style => { default => 'reference', type => SCALAR },
force_inline_anchor_links => { default => 0, type => BOOLEAN },
image_style => { default => 'reference', type => SCALAR },
image_tag_fallback => { default => 1, type => BOOLEAN },
unordered_list_style => { default => 'asterisk', type => SCALAR },
ordered_list_style => { default => 'sequential', type => SCALAR },
} }
my @common_attrs = qw/ id class lang dir title style /;
sub rules {
my $self = shift;
my %rules = (
hr => { replace => "\n\n----\n\n" },
br => { preserve => 1, empty => 1 },
p => { block => 1, trim => 'both', line_format => 'multi', line_prefix => \&_p_prefix },
blockquote => { block => 1, trim => 'both', line_format => 'blocks', line_prefix => '> ' },
ul => { block => 1, line_format => 'multi' },
ol => { alias => 'ul' },
li => { start => \&_li_start, trim => 'leading' },
i => { start => '_', end => '_' },
em => { alias => 'i' },
b => { start => '**', end => '**' },
strong => { alias => 'b' },
code => { start => '`', end => '`' },
a => { replace => \&_link },
img => { replace => \&_img },
);
for( 1..6 ) {
$rules{"h$_"} = { start => \&_header_start, end => \&_header_end, trim => 'both', block => 1 };
}
for( qw/ table caption tr th td / ) {
$rules{$_} = { preserve => 1, attrs => \@common_attrs, start => "\n", end => "\n", line_format => 'multi' };
}
return \%rules;
}
sub _header_start {
my( $self, $node, $rules ) = @_;
return '' unless $self->header_style eq 'atx';
( my $level = $node->tag ) =~ s/\D//g;
return unless $level;
my $hr = ('#') x $level;
return "$hr ";
}
sub _header_end {
my( $self, $node, $rules ) = @_;
return '' unless $self->header_style eq 'setext';
( my $level = $node->tag ) =~ s/\D//g;
return unless $level;
my $symbol = $level == 1 ? '=' : '-';
my $len = length $self->get_elem_contents($node);
my $bar = ($symbol) x $len;
return "\n$bar\n";
}
sub _link {
my( $self, $node, $rules ) = @_;
my $url = $self->_abs2rel($node->attr('href') || '');
my $text = $self->get_elem_contents($node);
my $title = $node->attr('title') || '';
my $style = $self->link_style;
$style = 'inline' if $url =~ /^\#/ and $self->force_inline_anchor_links;
if( $url eq $text ) {
return sprintf "<%s>", $url;
} elsif( $style eq 'inline' ) {
return sprintf "[%s](%s %s)", $text, $url, $title if $title;
return sprintf "[%s](%s)", $text, $url;
} elsif( $style eq 'reference' ) {
my $id = $self->_next_link_id;
$self->_add_link( { id => $id, url => $url, title => $title } );
return sprintf "[%s][%s]", $text, $id;
}
}
sub _last_link_id { shift->_attr( { internal => 1 }, _last_link_id => @_ ) }
sub _links { shift->_attr( { internal => 1 }, _links => @_ ) }
sub _next_link_id {
my $self = shift;
my $next_id = ($self->_last_link_id || 0) + 1;
$self->_last_link_id( $next_id );
return $next_id;
}
sub _add_link {
my( $self, $link ) = @_;
$self->_links( [ @{ $self->_links || [] }, $link ] );
}
sub _img {
my( $self, $node, $rules ) = @_;
my $url = $node->attr('src') || '';
my $text = $node->attr('alt') || '';
my $title = $node->attr('title') || '';
my $width = $node->attr('width') || '';
my $height = $node->attr('height') || '';
if( $width || $height and $self->image_tag_fallback ) {
return "
get_attr_str( $node, qw/ src width height alt /, @common_attrs )." />";
} elsif( $self->image_style eq 'inline' ) {
return sprintf "", $text, $url, $title if $title;
return sprintf "", $text, $url;
} elsif( $self->image_style eq 'reference' ) {
my $id = $self->_next_link_id;
$self->_add_link( { id => $id, url => $url, title => $title } );
return sprintf "![%s][%s]", $text, $id;
}
}
sub _li_start {
my( $self, $node, $rules ) = @_;
my @parent_lists = $node->look_up( _tag => qr/ul|ol/ );
my $prefix = (' ') x ( @parent_lists - 1 );
my $bullet = '';
$bullet = $self->_ul_li_start if $node->parent and $node->parent->tag eq 'ul';
$bullet = $self->_ol_li_start($node->parent) if $node->parent and $node->parent->tag eq 'ol';
return "\n$prefix$bullet ";
}
sub _ul_li_start {
my $self = shift;
my $style = $self->unordered_list_style;
return '*' if $style eq 'asterisk';
return '+' if $style eq 'plus';
return '-' if $style eq 'dash';
die "no such unordered list style: '$style'";
}
my %ol_count = ( );
sub _ol_li_start {
my( $self, $ol ) = @_;
my $style = $self->ordered_list_style;
if( $style eq 'one-dot' ) {
return '1.';
} elsif( $style eq 'sequential' ) {
my $count = ++$ol_count{$ol};
return "$count.";
} else {
die "no such ordered list style: $style";
}
}
sub _p_prefix {
my( $wc, $node, $rules ) = @_;
return $node->look_up( _tag => 'li' ) ? ' ' : '';
}
sub preprocess_node {
my( $self, $node ) = @_;
return unless $node->tag and $node->parent and $node->parent->tag;
if( $node->parent->tag eq 'blockquote' and $self->_is_phrase_tag($node->tag) ) {
$self->_envelop_elem( $node, HTML::Element->new('p') );
} elsif( $node->tag eq '~text' ) {
$self->_escape_text($node);
}
}
sub _envelop_elem {
my( $self, $node, $new_parent ) = @_;
my $h = $node->replace_with($new_parent);
$new_parent->push_content($h);
}
my @escapes = qw( \\ \` * _ { } ); # '#', '.', '[', and '!' are handled specially
sub _escape_text {
my( $self, $node ) = @_;
my $text = $node->attr('text') || '';
my $escapes = join '', @escapes;
$text =~ s/([\Q$escapes\E])/\\$1/g;
$text =~ s/^([\d]+)\./$1\\./;
$text =~ s/^\#/\\#/;
$text =~ s/\!\[/\\![/g;
$text =~ s/\]\[/]\\[/g;
$node->attr( text => $text );
}
sub postprocess_output {
my( $self, $outref ) = @_;
$self->_add_references($outref);
}
sub _add_references {
my( $self, $outref ) = @_;
my @links = @{ $self->_links || [] };
return unless @links;
my $links = '';
foreach my $link ( @links ) {
my $id = $link->{id} || '';
my $url = $link->{url} || '';
my $title = $link->{title} || '';
if( $title ) {
$links .= sprintf " [%s]: %s \"%s\"\n", $id, $url, $title;
} else {
$links .= sprintf " [%s]: %s\n", $id, $url;
}
}
$self->_links( [] );
$self->_last_link_id( 0 );
$$outref .= "\n\n$links";
$$outref =~ s/\s+$//gs;
}
sub _is_phrase_tag {
my $tag = pop || '';
return $HTML::Tagset::isPhraseMarkup{$tag} || $tag eq '~text';
}
sub _abs2rel {
my( $self, $uri ) = @_;
return $uri unless $self->base_uri;
return URI->new($uri)->rel($self->base_uri)->as_string;
}
=head1 AUTHOR
David J. Iberri, C<< >>
=head1 BUGS
Please report any bugs or feature requests to
C, or through the web interface at
L.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc HTML::WikiConverter::Markdown
You can also look for information at:
=over 4
=item * AnnoCPAN: Annotated CPAN documentation
L
=item * CPAN Ratings
L
=item * RT: CPAN's request tracker
L
=item * Search CPAN
L
=back
=head1 COPYRIGHT & LICENSE
Copyright 2006 David J. Iberri, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1;
HTML-WikiConverter-Markdown-0.02/Changes 0100644 0004734 0023422 00000000416 10460003052 017013 0 ustar diberri hoc # Revision history for HTML::WikiConverter::Markdown
date: Thu Jul 20 18:00:00 EST 2006
version: 0.02
changes:
- require 0.60
- add attribute types
date: Wed Jun 07 10:00:00 EST 2006
version: 0.01
changes:
- initial release (fulfill feature request: bug #18111)
HTML-WikiConverter-Markdown-0.02/MANIFEST 0100644 0004734 0023422 00000000301 10441556574 016667 0 ustar diberri hoc Changes
MANIFEST
META.yml # Will be created by "make dist"
Makefile.PL
README
lib/HTML/WikiConverter/Markdown.pm
t/00-load.t
t/boilerplate.t
t/markdown.t
t/pod-coverage.t
t/pod.t
t/runtests.pl
HTML-WikiConverter-Markdown-0.02/Makefile.PL 0100644 0004734 0023422 00000001243 10460003150 017470 0 ustar diberri hoc use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'HTML::WikiConverter::Markdown',
AUTHOR => 'David J. Iberri ',
VERSION_FROM => 'lib/HTML/WikiConverter/Markdown.pm',
ABSTRACT_FROM => 'lib/HTML/WikiConverter/Markdown.pm',
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'HTML::WikiConverter' => 0.60,
'HTML::Tagset' => 0,
'Params::Validate' => 0,
'URI' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'HTML-WikiConverter-Markdown-*' },
);
HTML-WikiConverter-Markdown-0.02/README 0100644 0004734 0023422 00000002662 10460002702 016406 0 ustar diberri hoc HTML::WikiConverter::Markdown
=============================
This module adds HTML->Markdown conversion to the HTML::WikiConverter
module.
SYNOPSIS
Converting HTML to wiki markup is easy:
use HTML::WikiConverter;
my $wc = new HTML::WikiConverter( dialect => 'Markdown' );
print $wc->html2wiki( "hello" );
Or from the command line:
% html2wiki --dialect Markdown input.html > output.wiki
There's also a web interface if you're so inclined:
http://diberri.dyndns.org/wikipedia/html2wiki/
DEPENDENCIES
* HTML::WikiConverter version 0.60
* HTML::Tagset
* URI
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the perldoc command.
perldoc HTML::WikiConverter::Markdown
You can also look for information at:
Search CPAN
http://search.cpan.org/dist/HTML-WikiConverter-Markdown
CPAN Request Tracker:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-WikiConverter-Markdown
AnnoCPAN, annotated CPAN documentation:
http://annocpan.org/dist/HTML-WikiConverter-Markdown
CPAN Ratings:
http://cpanratings.perl.org/d/HTML-WikiConverter-Markdown
COPYRIGHT AND LICENCE
Copyright (C) 2006 David J. Iberri
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.