]> sipb.mit.edu Git - ikiwiki.git/commitdiff
dirname, basename, bestlink, linkify, pagetitle, titlepage.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 4 May 2006 18:51:26 +0000 (18:51 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 4 May 2006 18:51:26 +0000 (18:51 +0000)
* Allow links of the form [[some page|page]], with whitespace in the link
  text.

IkiWiki.pm
basewiki/wikilink.mdwn
debian/changelog
ikiwiki
t/linkify.t [new file with mode: 0755]
t/pagetitle.t [new file with mode: 0755]
t/titlepage.t [new file with mode: 0755]

index 960d26de93f94e4e95a44098b2b616a3b089f5a2..6a62d9f0ed2ecd155f6eec6f1a7f16defecdf77c 100644 (file)
@@ -9,6 +9,42 @@ use HTML::Template;
 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
             %renderedfiles %pagesources %depends %hooks};
 
 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");
 sub checkconfig () { #{{{
        if ($config{cgi} && ! length $config{url}) {
                error("Must specify url to wiki with --url when using --cgi\n");
index 21f10a7dd7af9edc1c66dee0d4a428d873540920..abdfe6fd281e7d9fb6ded4cf3e346ed2f9c19e44 100644 (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
 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]]
index 3e65b39ae46dbd1b8068c4ef9c830ec49b246ad2..fb4a734bff52de6a80d6d3ad67253fe40cc3ee95 100644 (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,
   * 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
   * 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.
     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
 
 
 ikiwiki (1.0) unstable; urgency=low
 
diff --git a/ikiwiki b/ikiwiki
index 745dfddd4ca870376844d913516d5962e2682f8e..4801c5f92e734df7bf7f9c170519c59b31875c77 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -13,42 +13,7 @@ sub usage () { #{{{
 
 sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
 
 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},
                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 (executable)
index 0000000..c231d73
--- /dev/null
@@ -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 (executable)
index 0000000..1bb4421
--- /dev/null
@@ -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 (executable)
index 0000000..6e1856a
--- /dev/null
@@ -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");