aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm36
-rw-r--r--basewiki/wikilink.mdwn4
-rw-r--r--debian/changelog6
-rwxr-xr-xikiwiki37
-rwxr-xr-xt/linkify.t74
-rwxr-xr-xt/pagetitle.t12
-rwxr-xr-xt/titlepage.t12
7 files changed, 141 insertions, 40 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 960d26de9..6a62d9f0e 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -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");
diff --git a/basewiki/wikilink.mdwn b/basewiki/wikilink.mdwn
index 21f10a7dd..abdfe6fd2 100644
--- a/basewiki/wikilink.mdwn
+++ b/basewiki/wikilink.mdwn
@@ -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]]
diff --git a/debian/changelog b/debian/changelog
index 3e65b39ae..fb4a734bf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/ikiwiki b/ikiwiki
index 745dfddd4..4801c5f92 100755
--- a/ikiwiki
+++ b/ikiwiki
@@ -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},
diff --git a/t/linkify.t b/t/linkify.t
new file mode 100755
index 000000000..c231d734b
--- /dev/null
+++ b/t/linkify.t
@@ -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");
diff --git a/t/pagetitle.t b/t/pagetitle.t
new file mode 100755
index 000000000..1bb4421e4
--- /dev/null
+++ b/t/pagetitle.t
@@ -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");
diff --git a/t/titlepage.t b/t/titlepage.t
new file mode 100755
index 000000000..6e1856a15
--- /dev/null
+++ b/t/titlepage.t
@@ -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");