aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-11-30 15:42:42 -0400
committerJoey Hess <joey@kitenet.net>2011-11-30 15:47:13 -0400
commit4cb343f3482edc3786ea46eea7efb7762d349164 (patch)
tree4fa15a5bf4f8bfcfca3e811784429a356fc29738 /IkiWiki/Plugin
parent997116f1602e1c1340d9a9839908f3350e2eb1ca (diff)
downloadikiwiki-4cb343f3482edc3786ea46eea7efb7762d349164.tar
ikiwiki-4cb343f3482edc3786ea46eea7efb7762d349164.tar.gz
graphviz: Support wikilinks embedded in the graph.
(Sponsored by The TOVA Company.)
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/graphviz.pm39
1 files changed, 37 insertions, 2 deletions
diff --git a/IkiWiki/Plugin/graphviz.pm b/IkiWiki/Plugin/graphviz.pm
index 4268f42ed..0889bc9fc 100644
--- a/IkiWiki/Plugin/graphviz.pm
+++ b/IkiWiki/Plugin/graphviz.pm
@@ -11,7 +11,7 @@ use IPC::Open2;
sub import {
hook(type => "getsetup", id => "graphviz", call => \&getsetup);
hook(type => "needsbuild", id => "version", call => \&needsbuild);
- hook(type => "preprocess", id => "graph", call => \&graph);
+ hook(type => "preprocess", id => "graph", call => \&graph, scan => 1);
}
sub getsetup () {
@@ -94,7 +94,42 @@ sub render_graph (\%) {
sub graph (@) {
my %params=@_;
- $params{src} = "" unless defined $params{src};
+
+ # Support wikilinks in the graph source.
+ my $src=$params{src};
+ $src="" unless defined $src;
+ $src=IkiWiki::linkify($params{page}, $params{destpage}, $params{src});
+ return unless defined wantarray; # scan mode short-circuit
+ if ($src ne $params{src}) {
+ # linkify makes html links, but graphviz wants plain
+ # urls. This is, frankly a hack: Process source as html,
+ # throw out everything inside tags that is not a href.
+ my $s;
+ my $nested=0;
+ use HTML::Parser;
+ error $@ if $@;
+ my $p=HTML::Parser->new(api_version => 3);
+ $p->handler(start => sub {
+ my %attrs=%{shift()};
+ if (exists $attrs{href}) {
+ $s.="\"$attrs{href}\"";
+ }
+ $nested++;
+ }, "attr");
+ $p->handler(end => sub {
+ $nested--;
+ });
+ $p->handler(default => sub {
+ $s.=join("", @_) unless $nested;
+ }, "text");
+ $p->parse($src);
+ $p->eof;
+ $params{src}=$s;
+ }
+ else {
+ $params{src}=$src;
+ }
+
$params{type} = "digraph" unless defined $params{type};
$params{prog} = "dot" unless defined $params{prog};
error gettext("prog not a valid graphviz program") unless $graphviz_programs{$params{prog}};