3 This plugin provides the msc [[ikiwiki/directive]].
4 This directive allows embedding [mscgen](http://www.mcternan.me.uk/mscgen/)
5 message sequence chart graphs in a page.
7 Here's an mscgen source example.
12 a [label="Client"],b [label="Server"];
17 a<=b [label="ack1, nack2"];
18 a=>b [label="data2", arcskip="1"];
24 And here's the resulting graph.
29 a [label="Client"],b [label="Server"];
34 a<=b [label="ack1, nack2"];
35 a=>b [label="data2", arcskip="1"];
41 Security implications: to be determined.
43 This plugin uses the [[!cpan Digest::SHA]] perl module.
45 This plugin borrows heavily from the [[graphviz|plugins/graphviz]] plugin written by [[JoshTriplett]].
47 I couldn't upload an attachment, so here's the plugin source.
51 # mscgen plugin for ikiwiki: render mscgen source as an image.
53 # Derived from graphviz plugin by Josh Triplett.
54 package IkiWiki::Plugin::mscgen;
62 hook(type => "getsetup", id => "mscgen", call => \&getsetup);
63 hook(type => "preprocess", id => "msc", call => \&graph);
75 sub render_graph (\%) {
76 my %params = %{(shift)};
82 # Use the sha1 of the mscgen code as part of its filename.
83 eval q{use Digest::SHA};
85 my $dest=$params{page}."/msc-".
86 IkiWiki::possibly_foolish_untaint(Digest::SHA::sha1_hex($src)).
88 will_render($params{page}, $dest);
90 if (! -e "$config{destdir}/$dest") {
93 $SIG{PIPE}=sub { $sigpipe=1 };
94 $pid=open2(*IN, *OUT, 'mscgen', '-Tpng', '-i-', '-o-');
96 # open2 doesn't respect "use open ':utf8'"
97 binmode (OUT, ':utf8');
110 $SIG{PIPE}="DEFAULT";
111 error gettext("failed to run mscgen") if $sigpipe;
113 if (! $params{preview}) {
114 writefile($dest, $config{destdir}, $png, 1);
117 # in preview mode, embed the image in a data uri
118 # to avoid temp file clutter
119 eval q{use MIME::Base64};
121 return "<img src=\"data:image/png;base64,".
122 encode_base64($png)."\" />";
126 return "<img src=\"".urlto($dest, $params{destpage})."\" />\n";
131 $params{src} = "" unless defined $params{src};
132 return render_graph(%params);