dirname, basename, bestlink, linkify, pagetitle, titlepage.

* Allow links of the form [[some page|page]], with whitespace in the link
  text.
master
joey 2006-05-04 18:51:26 +00:00
parent 0e8d8be117
commit 642f73a39f
7 changed files with 141 additions and 40 deletions

View File

@ -9,6 +9,42 @@ use HTML::Template;
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
%renderedfiles %pagesources %depends %hooks};
sub defaultconfig () { #{{{
wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/,
wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
verbose => 0,
wikiname => "wiki",
default_pageext => ".mdwn",
cgi => 0,
rcs => 'svn',
notify => 0,
url => '',
cgiurl => '',
historyurl => '',
diffurl => '',
anonok => 0,
rss => 0,
sanitize => 1,
rebuild => 0,
refresh => 0,
getctime => 0,
wrapper => undef,
wrappermode => undef,
svnrepo => undef,
svnpath => "trunk",
srcdir => undef,
destdir => undef,
templatedir => "/usr/share/ikiwiki/templates",
underlaydir => "/usr/share/ikiwiki/basewiki",
setup => undef,
adminuser => undef,
adminemail => undef,
plugin => [qw{inline}],
headercontent => '',
} #}}}
sub checkconfig () { #{{{
if ($config{cgi} && ! length $config{url}) {
error("Must specify url to wiki with --url when using --cgi\n");

View File

@ -15,5 +15,5 @@ Note that if the file linked to by a WikiLink looks like an image, it will
be displayed inline on the page.
It's also possible to write a WikiLink that uses something other than the
page name as the link text. For example "\[[foo_bar|SandBox]]" links to the
SandBox page, but the link will appear like this: [[foo_bar|SandBox]]
page name as the link text. For example "\[[foo bar|SandBox]]" links to the
SandBox page, but the link will appear like this: [[foo bar|SandBox]]

6
debian/changelog vendored
View File

@ -27,7 +27,7 @@ ikiwiki (1.1) UNRELEASED; urgency=low
* Split off an IkiWiki.pm out of ikiwiki and have all the other modules use
it, this will allow for adding a unit test suite.
* Add unit tests for several core functions, including globlist_match,
dirname, basename, and bestlink.
dirname, basename, bestlink, linkify, pagetitle, titlepage.
* Smart globlist merging.
* Patch from Thomas Schwinge to switch from --svn to --rcs=svn, etc,
to pave the way for adding other RCS support. This also changes the
@ -41,8 +41,10 @@ ikiwiki (1.1) UNRELEASED; urgency=low
switch.
* Added smiley plugin, nicely controlled and documented by the smileys page.
* Copied in some smileys from Moin Moin.
* Allow links of the form [[some page|page]], with whitespace in the link
text.
-- Joey Hess <joeyh@debian.org> Tue, 2 May 2006 14:13:59 -0400
-- Joey Hess <joeyh@debian.org> Thu, 4 May 2006 14:46:46 -0400
ikiwiki (1.0) unstable; urgency=low

37
ikiwiki
View File

@ -13,42 +13,7 @@ sub usage () { #{{{
sub getconfig () { #{{{
if (! exists $ENV{WRAPPED_OPTIONS}) {
%config=(
wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
verbose => 0,
wikiname => "wiki",
default_pageext => ".mdwn",
cgi => 0,
rcs => 'svn',
notify => 0,
url => '',
cgiurl => '',
historyurl => '',
diffurl => '',
anonok => 0,
rss => 0,
sanitize => 1,
rebuild => 0,
refresh => 0,
getctime => 0,
wrapper => undef,
wrappermode => undef,
svnrepo => undef,
svnpath => "trunk",
srcdir => undef,
destdir => undef,
templatedir => "/usr/share/ikiwiki/templates",
underlaydir => "/usr/share/ikiwiki/basewiki",
setup => undef,
adminuser => undef,
adminemail => undef,
plugin => [qw{inline}],
headercontent => '',
);
%config=defaultconfig();
eval q{use Getopt::Long};
GetOptions(
"setup|s=s" => \$config{setup},

74
t/linkify.t 100755
View File

@ -0,0 +1,74 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 11;
sub linkify ($$$) {
my $content=shift;
my $page=shift;
my @existing_pages=@{shift()};
# This is what linkify and htmllink need set right now to work.
# This could change, if so, update it..
%IkiWiki::links=();
foreach my $page (@existing_pages) {
$IkiWiki::links{$page}=[];
$IkiWiki::renderedfiles{"$page.mdwn"}=$page;
}
%IkiWiki::config=IkiWiki::defaultconfig();
return IkiWiki::linkify($content, $page);
}
sub links_to ($$) {
my $link=shift;
my $content=shift;
if ($content =~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
return 1;
}
else {
print STDERR "# expected link to $link in $content\n";
return;
}
}
sub not_links_to ($$) {
my $link=shift;
my $content=shift;
if ($content !~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
return 1;
}
else {
print STDERR "# expected no link to $link in $content\n";
return;
}
}
sub links_text ($$) {
my $text=shift;
my $content=shift;
if ($content =~ m!>\Q$text\E</a>!) {
return 1;
}
else {
print STDERR "# expected link text $text in $content\n";
return;
}
}
BEGIN { use_ok("IkiWiki::Render"); }
ok(links_to("bar", linkify("link to [[bar]] ok", "foo", ["foo", "bar"])), "ok link");
ok(not_links_to("bar", linkify("link to \\[[bar]] ok", "foo", ["foo", "bar"])), "escaped link");
ok(links_to("page=bar", linkify("link to [[bar]] ok", "foo", ["foo"])), "broken link");
ok(links_to("bar", linkify("link to [[baz]] and [[bar]] ok", "foo", ["foo", "baz", "bar"])), "dual links");
ok(links_to("baz", linkify("link to [[baz]] and [[bar]] ok", "foo", ["foo", "baz", "bar"])), "dual links");
ok(links_to("bar", linkify("link to [[some_page|bar]] ok", "foo", ["foo", "bar"])), "named link");
ok(links_text("some page", linkify("link to [[some_page|bar]] ok", "foo", ["foo", "bar"])), "named link text");
ok(links_to("bar", linkify("link to [[some page|bar]] ok", "foo", ["foo", "bar"])), "named link, with whitespace");
ok(links_text("some page", linkify("link to [[some page|bar]] ok", "foo", ["foo", "bar"])), "named link text, with whitespace");
ok(links_text("Some long, & complex page name.", linkify("link to [[Some long, & complex page name.|bar]] ok, and this is not a link]] here", "foo", ["foo", "bar"])), "complex named link text");

12
t/pagetitle.t 100755
View File

@ -0,0 +1,12 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 6;
BEGIN { use_ok("IkiWiki"); }
is(IkiWiki::pagetitle("foo_bar"), "foo bar");
is(IkiWiki::pagetitle("foo_bar_baz"), "foo bar baz");
is(IkiWiki::pagetitle("foo_bar__33__baz"), "foo bar&#33;baz");
is(IkiWiki::pagetitle("foo_bar__1234__baz"), "foo bar&#1234;baz");
is(IkiWiki::pagetitle("foo_bar___33___baz"), "foo bar &#33; baz");

12
t/titlepage.t 100755
View File

@ -0,0 +1,12 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 6;
BEGIN { use_ok("IkiWiki"); }
is(IkiWiki::titlepage("foo bar"), "foo_bar");
is(IkiWiki::titlepage("foo bar baz"), "foo_bar_baz");
is(IkiWiki::titlepage("foo bar/baz"), "foo_bar/baz");
is(IkiWiki::titlepage("foo bar&baz"), "foo_bar__38__baz");
is(IkiWiki::titlepage("foo bar & baz"), "foo_bar___38___baz");