Skip Menu |
 

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

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

People
Owner: diberri [...] cpan.org
Requestors: mjbudden [...] gmail.com
Cc:
AdminCc:

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



Subject: feature-request: Support for TiddlyWiki 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 259b
I've attached an initial cut of the TiddlyWiki converter. On Tue Jan 22 12:49:17 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 TiddlyWiki.pm
text/x-perl 5.9k
package HTML::WikiConverter::TiddlyWiki; use base 'HTML::WikiConverter'; use warnings; use strict; use URI; use File::Basename; our $VERSION = '0.01'; =head1 NAME HTML::WikiConverter::TiddlyWiki - Convert HTML to TiddlyWiki markup =head1 SYNOPSIS use HTML::WikiConverter; my $wc = new HTML::WikiConverter( dialect => 'TiddlyWiki' ); print $wc->html2wiki( $html ); =head1 DESCRIPTION This module contains rules for converting HTML into TiddlyWiki markup. See L<HTML::WikiConverter> for additional usage details. =cut sub rules { my %rules = ( hr => { replace => "\n----\n" }, h1 => { start => '! ', block => 1, trim => 'both', line_format => 'single' }, h2 => { start => '!! ', block => 1, trim => 'both', line_format => 'single' }, h3 => { start => '!!! ', block => 1, trim => 'both', line_format => 'single' }, h4 => { start => '!!!! ', block => 1, trim => 'both', line_format => 'single' }, h5 => { start => '!!!!! ', block => 1, trim => 'both', line_format => 'single' }, h6 => { start => '!!!!!! ', 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 => "__"}, 'sub' => { start => "~~", end => "~~"}, sup => { start => "^^", end => "^^"}, strike => { start => "--", end => "--"}, code => { start => "\n{{{\n", end => "\n}}}\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 = "["; $ret .= "<" if $align eq 'left'; $ret .= ">" if $align eq 'right'; $ret .= "img["; $ret .= "$title|" if $title; $ret .= "$img]]"; } # 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 "[[$text|$url]]"; } # tables derived from PmWiki sub _td_start { my( $self, $node, $rules ) = @_; my $colspan = $node->attr('colspan') || 1; my $prefix = ( '>' ) x ($colspan-1); $prefix .= '|' if $colspan > 1; $prefix .= $node->tag eq 'th' ? '!' : ''; my $align = $node->attr('align') || 'none'; 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 'none'; $prefix .= '' if $align eq 'left'; $prefix .= ' ' if $align eq 'center'; $prefix .= ' ' if $align eq 'right'; return $prefix; } sub _td_end { my( $self, $node, $rules ) = @_; my $suffix = ''; my $align = $node->attr('align') || 'none'; $suffix .= '|' if $align eq 'none'; $suffix .= ' |' if $align eq 'left'; $suffix .= ' |' if $align eq 'center'; $suffix .= '|' if $align eq 'right'; 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-tiddlywiki at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-WikiConverter-TiddlyWiki>. 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::TiddlyWiki You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L<http://annocpan.org/dist/HTML-WikiConverter-TiddlyWiki> =item * CPAN Ratings L<http://cpanratings.perl.org/d/HTML-WikiConverter-TiddlyWiki> =item * RT: CPAN's request tracker L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-WikiConverter-TiddlyWiki> =item * Search CPAN L<http://search.cpan.org/dist/HTML-WikiConverter-TiddlyWiki> =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 tiddlywiki.t
text/x-perl 4.9k
local $/; require 't/runtests.pl'; runtests( data => <DATA>, dialect => 'TiddlyWiki' ); 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__ strike __H__ <html><strike>strike</strike></html> __W__ --strike-- __NEXT__ sub __H__ <html><sub>subscript</sub></html> __W__ ~~subscript~~ __NEXT__ superscript __H__ <html><sup>superscript</sup></html> __W__ ^^superscript^^ __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__ {{{ $name = 'stan'; }}} __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" /> __W__ [img[http://www.example.com/logo.png]] __NEXT__ img alt __H__ <img src="http://www.example.com/logo.png" title="logo.png" /> __W__ [img[logo.png|http://www.example.com/logo.png]] __NEXT__ img left __H__ <img src="http://www.example.com/logo.png" alt="logo.png" align="left" /> __W__ [<img[http://www.example.com/logo.png]] __NEXT__ img right __H__ <img src="http://www.example.com/logo.png" alt="logo.png" align="right" /> __W__ [>img[http://www.example.com/logo.png]] __NEXT__ img caption __H__ <img src="http://www.example.com/logo.png" alt="logo" title="caption for logo" /> __W__ [img[caption for logo|http://www.example.com/logo.png]] __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|
Download (untitled) / with headers
text/plain 181b
Thank you for this report and the code that accompanies it. Your best bet toward getting this module released would be to make it available via the CPAN at http://cpan.org. -- Dave


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.