package Kwiki::Display; use Kwiki::Plugin -Base; use mixin 'Kwiki::Installer'; use Markdown; use Digest::MD5 qw(md5_hex); our $version = "0.001"; const config_file => 'display.yaml'; const class_id => 'display'; const class_title => 'Page Display'; sub register { my $registry = shift; $registry->add(action => 'display'); $registry->add(toolbar => 'home_button', template => 'home_button.html', ); $registry->add(preference => $self->display_changed_by); } sub display_changed_by { my $p = $self->new_preference('display_changed_by'); $p->query('Show a "Changed by ..." section on each page?'); $p->default(0); return $p; } sub display { my $page = $self->pages->current; return $self->redirect('') unless $page; my $page_title = $page->title; my $page_uri = $page->uri; return $self->redirect("action=edit;page_name=$page_uri") if not($page->exists) and $self->have_plugin('edit'); my $script = $self->config->script_name; my $screen_title = $self->hub->have_plugin('search') ? "$page_title" : $page_title; # eval { # $page->content; # }; # if ($@) { # my $main_page = $self->config->main_page; # die $@ if $page->title eq $main_page; # return $self->redirect($main_page); # } my %links; # Render content using markdown my $content = $page->content(); # find bracketed links $content =~ s{\[\[([^\]]+)\]\[([^\]]*)\]\]}{ my $link = qq($2); my $digest = md5_hex($link); $links{ $digest } = $link; join "-", ( "xxx", $digest, "xxx" ); }eg; # find plain http:// style links including images $content =~ s{\b(http://[^\s]+)}{ my $link = $1; if ( $link =~ m,(\.jpg|\.png|\.gif)$, ) { $link = qq(); } else { $link = qq($link); } my $digest = md5_hex($link); $links{ $digest } = $link; join "-", ( "xxx", $digest, "xxx" ); }eg; # find wiki words $content =~ s{([A-Z][A-Za-z]*[A-Z][A-Za-z0-9]*)\b(?=[^\]])}{ my $link = qq($1); my $digest = md5_hex($link); $links{ $digest } = $link; join "-", ( "xxx", $digest, "xxx" ); }eg; $content = Markdown::Markdown( $content ); # replace the md5s with the links my $expression = join "|", keys %links; $content =~ s{xxx-($expression)-xxx}{ $links{ $1 } }eg; $self->render_screen( screen_title => $screen_title, page_html => $content, ); } __DATA__ =head1 NAME Kwiki::Display - MarkDown Kwiki Display module =head1 SYNOPSIS Mark up kwiki pages with Markdown. =head1 DESCRIPTION This project is still alpha. Format kwiki pages using markdown instead of the default kwiki parser. This does not, however use markdown for generating links. Links follow common wiki conventions, e.g. WikiWords and bracketed links [[url][link description]]. Also, urls are turned into links, and urls that point to images are turned into images tags to display the images inline. I borrowed this guy's parsing theory: http://70.84.29.148:2500/instiki/show/RenderPatch During the parsing, as link patterns are encountered in the text, they are removed from the text, an md5 is computed for the link, and the link is replaced with the md5. Once all links have been removed, the text is sent through markdown, and then the md5s are replaced with the links. =head1 BUGS There is no way to ever disable linking. Links can not use any of the standard markdown convention, e.g. [description](link). Also breaks wafl. Also my wiki word matching pattern is extremely promiscious. Any word with more than one captial is a link. If ya don't like it, plug in your own regular expression. ;> =head1 SEE ALSO - http://www.geekfarm.org/twiki/bin/view/Main/KwikiMarkdown - http://www.kwiki.org/ - http://daringfireball.net/projects/markdown/ =head1 AUTHOR VVu =head1 COPYRIGHT Copyright (c) 2005, VVu@geekfarm.org All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the geekfarm.org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =cut __template/tt2/home_button.html__ [% INCLUDE home_button_icon.html %] __template/tt2/home_button_icon.html__ Home __template/tt2/display_content.html__
[% page_html -%]
[% INCLUDE display_changed_by.html %] __template/tt2/display_changed_by.html__ [% IF self.preferences.display_changed_by.value %] [% page = hub.pages.current %]
Last changed by [% page.edit_by_link %] at [% page.edit_time %]
[% END %]