diff --git a/lib/Foswiki/Plugins/GraphvizPlugin/Config.spec b/lib/Foswiki/Plugins/GraphvizPlugin/Config.spec index 786412b..3f79fad 100644 --- a/lib/Foswiki/Plugins/GraphvizPlugin/Config.spec +++ b/lib/Foswiki/Plugins/GraphvizPlugin/Config.spec @@ -6,7 +6,7 @@ $Foswiki::cfg{GraphvizPlugin}{DotCmd} = '/usr/bin/dot -K%RENDERER|S% -T%TYPE|S% -o%OUTFILE|F% %INFILE|F%'; # **STRING** -$Foswiki::cfg{GraphvizPlugin}{ImageFormat} = ''; +$Foswiki::cfg{GraphvizPlugin}{ImageFormat} = ''; # **STRING** $Foswiki::cfg{GraphvizPlugin}{SvgFormat} = '$svg'; diff --git a/lib/Foswiki/Plugins/GraphvizPlugin/Core.pm b/lib/Foswiki/Plugins/GraphvizPlugin/Core.pm index 9235a5e..27b6922 100644 --- a/lib/Foswiki/Plugins/GraphvizPlugin/Core.pm +++ b/lib/Foswiki/Plugins/GraphvizPlugin/Core.pm @@ -188,28 +188,25 @@ sub GRAPHVIZ { my $width = $params->{width}; my $height = $params->{height}; - if ($type eq 'svg' && $doInline) { + if ($type eq 'svg') { my $svg = Foswiki::Func::readFile($outfilePath, 1); - $svg =~ s/<\?xml .*?>//g; - $svg =~ s///gs; - $result = $this->{svgFormat}; - - $result =~ s/\$svg/$svg/; - $result =~ s/width="[^"]*"/width="$width"/ if defined $width; - $result =~ s/height="[^"]*"/height="$height"/ if defined $height; - $result =~ s///g; + $svg =~ s///gs; + + $result = $this->{svgFormat}; + $result =~ s/\$svg/$svg/; + $result =~ s/width="[^"]*"/width="$width"/ if defined $width; + $result =~ s/height="[^"]*"/height="$height"/ if defined $height; + $result =~ s/{imageFormat} ); + } } else { - $result = $this->{imageFormat}; - - $style ||= ''; - $width ||= ''; - $height ||= ''; - $width = "width='".$width."'" if $width; - $height = "height='".$height."'" if $height; - - $result =~ s/\$style/$style/g; - $result =~ s/\$width/$width/g; - $result =~ s/\$height/$height/g; + $result = _updateFormat( $style, $width, $height, $this->{imageFormat} ); } $result =~ s/\$url/$url/g; @@ -220,6 +217,20 @@ sub GRAPHVIZ { return $result; } +sub _updateFormat { + my ( $style, $width, $height, $format ) = @_; + + $style = $style ? "style='$style' " : ''; + $width = $width ? "width='$width' " : ''; + $height = $height ? "height='$height' " : ''; + + $format =~ s/\$style/$style/g; + $format =~ s/\$width/$width/g; + $format =~ s/\$height/$height/g; + + return $format; +} + sub afterSaveHandler { my $this = shift; #my ( $text, $topic, $web, $error, $meta ) = @_;