Skip Menu |
 

This queue is for tickets about the HTML-WikiConverter CPAN distribution.

Report information
The Basics
Id: 32363
Status: new
Priority: 0/
Queue: HTML-WikiConverter

People
Owner: Nobody in particular
Requestors: mjbudden [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: feature-request: Support for Wikispaces syntax
Download (untitled) / with headers
text/plain 137b
Wikispaces support would be a useful addition. I'm doing some work in this area and when complete I'll attach it to this report. Martin
From: mjbudden [...] gmail.com
Download (untitled) / with headers
text/plain 265b
I've attached my first cut of the implementation and test code. On Wed Jan 16 15:22:10 2008, MartinBudden wrote: Show quoted text
> Wikispaces support would be a useful addition. > > I'm doing some work in this area and when complete I'll attach it to > this report. > > Martin
Download Wikispaces.pm
text/x-perl 5.6k
package HTML::WikiConverter::Wikispaces; use base 'HTML::WikiConverter'; use warnings; use strict; use URI; use File::Basename; our $VERSION = '0.01'; =head1 NAME HTML::WikiConverter::Wikispaces - Convert HTML to Wikispaces markup =head1 SYNOPSIS use HTML::WikiConverter; my $wc = new HTML::WikiConverter( dialect => 'Wikispaces' ); print $wc->html2wiki( $html ); =head1 DESCRIPTION This module contains rules for converting HTML into Wikispaces markup. See L<HTML::WikiConverter> for additional usage details. =cut sub rules { my %rules = ( hr => { replace => "\n----\n" }, h1 => { start => '= ', end => ' =', block => 1, trim => 'both', line_format => 'single' }, h2 => { start => '== ', end => ' ==', block => 1, trim => 'both', line_format => 'single' }, h3 => { start => '=== ', end => ' ===', block => 1, trim => 'both', line_format => 'single' }, # wikispaces does not support H4-H6, so just map to H3 h4 => { start => '=== ', end => ' ===', block => 1, trim => 'both', line_format => 'single' }, h5 => { start => '=== ', end => ' ===', block => 1, trim => 'both', line_format => 'single' }, h6 => { start => '=== ', end => ' ===', block => 1, trim => 'both', line_format => 'single' }, img => { replace => \&_image }, b => { start => "**", end => "**" }, strong => { alias => 'b' }, i => { start => "//", end => "//" }, em => { alias => 'i' }, u => { start => "__", end => "__"}, code => { start => "\n[[code]]\n", end => "\n[[code]]\n"}, tt => { start => "{{", end => "}}"}, # from PhpWiki blockquote => { start => \&_blockquote_start, block => 1, line_format => 'multi' }, p => { block => 1, trim => 'both', line_format => 'multi' }, a => { replace => \&_link }, ul => { line_format => 'multi', block => 1 }, ol => { alias => 'ul' }, li => { start => \&_li_start, trim => 'leading' }, # from PmWiki table => { block => 1 }, tr => { start => "\n||", line_format => 'single' }, td => { start => \&_td_start, end => \&_td_end, trim => 'both' }, th => { alias => 'td' }, pre => { preserve => 1 } ); return \%rules; } # Calculates the prefix that will be placed before each list item. # List item include ordered and unordered list items. sub _li_start { my( $self, $node, $rules ) = @_; my @parent_lists = $node->look_up( _tag => qr/ul|ol/ ); my $depth = @parent_lists; my $bullet = ''; $bullet = '*' if $node->parent->tag eq 'ul'; $bullet = '#' if $node->parent->tag eq 'ol'; my $prefix = ( $bullet ) x $depth; return "\n$prefix "; } # derived from MediaWiki sub _image { my( $self, $node, $rules ) = @_; return '' unless $node->attr('src'); #my $img = basename( URI->new($node->attr('src'))->path ); my $img = $node->attr('src'); my $alt = $node->attr('alt') || ''; my $align = $node->attr('align') || ''; my $title = $node->attr('title') || ''; my $ret = "[[image:$img"; $ret .= "|$alt" if $alt; $ret .= " align=\"$align\"" if $align; $ret .= " caption=\"$title\"" if $title; $ret .= "]]"; } # derived from PmWiki sub _anchor { my( $self, $node, $rules ) = @_; my $name = $node->attr('name') || ''; return "[[#$name]]"; } # derived from PmWiki sub _link { my( $self, $node, $rules ) = @_; return $self->_anchor($node, $rules) if $node->attr('name'); my $url = $node->attr('href') || ''; my $text = $self->get_elem_contents($node) || ''; return $url if $text eq $url; return "[[$url|$text]]"; } # tables derived from PmWiki sub _td_start { my( $self, $node, $rules ) = @_; my $colspan = $node->attr('colspan') || 1; my $prefix = ( '||' ) x ($colspan-1); $prefix .= $node->tag eq 'th' ? '~' : ''; my $align = $node->attr('align') || 'left'; my $style = $node->attr('style') || ''; $align = 'center' if $style eq 'text-align: center;'; $align = 'right' if $style eq 'text-align: right;'; $prefix .= '= ' if $align eq 'center'; $prefix .= '> ' if $align eq 'right'; $prefix .= ' ' if $align eq 'left'; return $prefix; } sub _td_end { my( $self, $node, $rules ) = @_; my $suffix = ' ||'; return $suffix; } # blockquote derived from PmWiki sub _blockquote_start { my( $self, $node, $rules ) = @_; my @parent_bqs = $node->look_up( _tag => 'blockquote' ); my $depth = @parent_bqs; my $start = ( '>' ) x $depth; return "\n".$start.' '; } =head1 AUTHOR Martin Budden, C<< <mjbudden at gmail.com> >> Heavily based on other HTML to wikitext modules written by David J. Iberri, C<< <diberri at cpan.org> >> =head1 BUGS Please report any bugs or feature requests to C<bug-html-wikiconverter-wikispaces at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-WikiConverter-Wikispaces>. 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::Wikispaces You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L<http://annocpan.org/dist/HTML-WikiConverter-Wikispaces> =item * CPAN Ratings L<http://cpanratings.perl.org/d/HTML-WikiConverter-Wikispaces> =item * RT: CPAN's request tracker L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-WikiConverter-Wikispaces> =item * Search CPAN L<http://search.cpan.org/dist/HTML-WikiConverter-Wikispaces> =back =head1 COPYRIGHT & LICENSE Copyright 2008 Martin Budden, all rights reserved. Heavily based on other HTML to wikitext modules written by David J. Iberri This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;
Download wikispaces.t
text/x-perl 4.9k
local $/; require 't/runtests.pl'; runtests( data => <DATA>, dialect => 'Wikispaces' ); close DATA; __DATA__ pre __H__ <html> <pre> Device ID : 0 Device Revision : 0 Firmware Revision : 1.71 IPMI Version : 1.0 Manufacturer ID : 674 Product ID : 1 (0x0001) Device Available : yes Provides Device SDRs : yes Additional Device Support : Sensor Device SDR Repository Device SEL Device FRU Inventory Device IPMB Event Receiver Aux Firmware Rev Info : 0x00 0x00 0x00 0x00 </pre> </html> __W__ <pre> Device ID : 0 Device Revision : 0 Firmware Revision : 1.71 IPMI Version : 1.0 Manufacturer ID : 674 Product ID : 1 (0x0001) Device Available : yes Provides Device SDRs : yes Additional Device Support : Sensor Device SDR Repository Device SEL Device FRU Inventory Device IPMB Event Receiver Aux Firmware Rev Info : 0x00 0x00 0x00 0x00 </pre> __NEXT__ bold __H__ <html><b>bold</b></html> __W__ **bold** __NEXT__ italics __H__ <html><i>italics</i></html> __W__ //italics// __NEXT__ underline __H__ <html><u>underline</u></html> __W__ __underline__ __NEXT__ bold and italics __H__ <html><b>bold</b> and <i>italics</i></html> __W__ **bold** and //italics// __NEXT__ bold-italics nested __H__ <html><i><b>bold-italics</b> nested</i></html> __W__ //**bold-italics** nested// __NEXT__ strong __H__ <html><strong>strong</strong></html> __W__ **strong** __NEXT__ emphasized __H__ <html><em>emphasized</em></html> __W__ //emphasized// __NEXT__ one-line phrasals __H__ <html><i>phrasals in one line</i></html> __W__ //phrasals in one line// __NEXT__ paragraph blocking __H__ <html><p>p1</p><p>p2</p></html> __W__ p1 p2 __NEXT__ lists __H__ <html><ul><li>1</li><li>2</li></ul></html> __W__ * 1 * 2 __NEXT__ nested lists __H__ <html><ul><li>1<ul><li>1a</li><li>1b</li></ul></li><li>2</li></ul> __W__ * 1 ** 1a ** 1b * 2 __NEXT__ nested lists (different types) __H__ <html><ul><li>1<ul><li>a<ol><li>i</li></ol></li><li>b</li></ul></li><li>2</li></ul></html> __W__ * 1 ** a ### i ** b * 2 __NEXT__ hr __H__ <html><hr /></html> __W__ ---- __NEXT__ code __H__ <html><code>$name = 'stan';</code></html> __W__ [[code]] $name = 'stan'; [[code]] __NEXT__ tt __H__ <html><tt>tt text</tt></html> __W__ {{tt text}} __NEXT__ pre __H__ <html><pre>this is preformatted text</pre></html> __W__ <pre>this is preformatted text</pre> __NEXT__ indent __H__ <html><blockquote>indented text</blockquote></html> __W__ > indented text __NEXT__ nested indent __H__ <html><blockquote>indented text <blockquote>double-indented</blockquote></blockquote></html> __W__ > indented text >> double-indented __NEXT__ h1 __H__ <h1>h1</h1> __W__ = h1 = __NEXT__ h2 __H__ <h2>h2</h2> __W__ == h2 == __NEXT__ h3 __H__ <h3>h3</h3> __W__ === h3 === __NEXT__ h4 __H__ <h4>h4</h4> __W__ === h4 === __NEXT__ h5 __H__ <h5>h5</h5> __W__ === h5 === __NEXT__ h6 __H__ <h6>h6</h6> __W__ === h6 === __NEXT__ img __H__ <img src="http://www.example.com/logo.png" alt="logo.png" /> __W__ [[image:http://www.example.com/logo.png|logo.png]] __NEXT__ img left __H__ <img src="http://www.example.com/logo.png" alt="logo.png" align="left" /> __W__ [[image:http://www.example.com/logo.png|logo.png align="left"]] __NEXT__ img right __H__ <img src="http://www.example.com/logo.png" alt="logo.png" align="right" /> __W__ [[image:http://www.example.com/logo.png|logo.png align="right"]] __NEXT__ img center __H__ <img src="http://www.example.com/logo.png" alt="logo.png" align="center" /> __W__ [[image:http://www.example.com/logo.png|logo.png align="center"]] __NEXT__ img caption __H__ <img src="http://www.example.com/logo.png" alt="logo" title="caption for logo" /> __W__ [[image:http://www.example.com/logo.png|logo caption="caption for logo"]] __NEXT__ external links 2 __H__ <html><a href="http://www.example.com">http://www.example.com</a></html> __W__ http://www.example.com __NEXT__ anchor __H__ <html><a name="anchor"></a></html> __W__ [[#anchor]] __NEXT__ simple tables __H__ <html> <table> <tr> <td> Name </td> <td> David </td></tr><tr><td> Age </td> <td> 24 </td> </tr> </table> </html> __W__ || Name || David || || Age || 24 || __NEXT__ tables 2 __H__ <html> <table> <tr> <th>heading1</th> <th>heading2</th> <th>heading3</th> </tr> <tr> <td>table cell</td> <td>table cell</td> <td>table cell</td> </tr> <tr> <td align="center">centered</td> <td align="right">right</td> <td>normal</td> </tr> <tr> <td colspan="2">spans 2 columns</td> <td>cell</td> </tr> <tr> <td>col1</td> <td>col2</td> <td>col3</td> </tr> <tr> <td>col1</td> <td>col2</td> <td>col3</td> </tr> </table> </html> __W__ ||~ heading1 ||~ heading2 ||~ heading3 || || table cell || table cell || table cell || ||= centered ||> right || normal || |||| spans 2 columns || cell || || col1 || col2 || col3 || || col1 || col2 || col3 ||


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.