From 234c41a29dd6413cc9967c1188dd830d4662edb5 Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Sat, 19 Jan 2008 05:22:55 +0000 Subject: [PATCH] Modified the documentation export script so it writes all images directly to ./images/*. Originally committed to SVN as r1777. --- docs/aegisub_convert_docs.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/aegisub_convert_docs.pl b/docs/aegisub_convert_docs.pl index ee4be8c6f..67ff4e36b 100644 --- a/docs/aegisub_convert_docs.pl +++ b/docs/aegisub_convert_docs.pl @@ -54,7 +54,7 @@ mkdir($base_dir) or die("Couldn't create directory ", $base_dir, ": $!") chdir($base_dir) or die("Couldn't change directory to ", $base_dir, ": $!"); -print("Starting downloading and conversion of documentation wiki to ", $base_dir, ".\n", +print("Starting downloading and conversion of documentation wiki to ", $base_dir, "\n", "This will probably take a while.\n"); @@ -234,7 +234,12 @@ sub parse_and_fix_html { } elsif ( ($tagname eq 'img') and exists($attrs{'src'}) ) { if ( $attrs{'src'} =~ m!^$quoted!i or (substr($attrs{'src'},0,1) eq '/') ) { - push(@links_to_modify, $attrs{'src'}); + # "flatten" image links + my $flatlink = $attrs{'src'}; + $flatlink =~ s!/docs/images/.+/(.+?\.(jpg|gif|png))!${base_dir}/images/$1!i; + my $quotedsrc = quotemeta($attrs{'src'}); + $content =~ s!$quotedsrc!$flatlink!; + #push(@links_to_modify, $attrs{'src'}); } else { next(LINKLIST); } @@ -291,6 +296,14 @@ sub write_to_disk { $path =~ m!(.*)/(.*?)\.\w{2,4}$!; my ($tree, $filename) = ($1, $2); + # is it an image link? + if ( $tree =~ m!\./images/! ) { + # hax it + $path =~ s!/images/.+/!/images/!i; + $tree =~ s!/images.+!/images!i; + } + + # I don't think this is necessary really mkpath($tree) unless ( -e $tree and -d $tree ); if ( $type =~ m!^text! ) {