You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by Mike Chamberlain <mi...@upmystreet.com> on 2003/05/09 13:28:55 UTC

Patch to htmldoc

Just making htmldoc use a better way to correct urls.

Now uses 'URI' and Apache::URI, so that will probably need to be added to
dependencies.

Index: lib/Apache/AxKit/Language/HtmlDoc.pm
===================================================================
RCS file: /home/cvspublic/xml-axkit/lib/Apache/AxKit/Language/HtmlDoc.pm,v
retrieving revision 1.4
diff -u -r1.4 HtmlDoc.pm
--- lib/Apache/AxKit/Language/HtmlDoc.pm        18 Feb 2003 22:37:22 -0000
1.4
+++ lib/Apache/AxKit/Language/HtmlDoc.pm        9 May 2003 11:27:38 -0000
@@ -12,6 +12,8 @@
 use Apache::AxKit::Language;
 use Apache::AxKit::LibXMLSupport;
 use Apache::AxKit::Provider;
+use Apache::URI;
+use URI;
 use XML::LibXSLT;
 use IPC::Run qw(run);
 use Cwd;
@@ -44,12 +46,44 @@
         $dom = $parser->parse_string($source_text, $r->uri());
     }
     $dom->process_xinclude();
+
+
XML::LibXSLT->register_function("perl://apache/axkit/language/htmldoc",
"url_fix", 
+               sub { my ($ref) = @_; 
+                       my $str = $ref;
+                       eval {
+                               my $r = Apache->request();
+                               my $realabs =
Apache::URI->parse($r)->unparse();
+                               $str = URI->new_abs( $ref, $realabs );

+                       };
+                       return "$str"; 
+               }
+       );
+
     my $style_dom = $parser->parse_string(<< 'EOX','.');
 <?xml version="1.0"?>
-<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
+<xsl:stylesheet version="1.0" 
+       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+       xmlns:x="http://www.w3.org/1999/xhtml"
+       xmlns:perl="perl://apache/axkit/language/htmldoc">
 <xsl:output method="html" encoding="ISO-8859-15"/>
-<xsl:template match="*"><xsl:copy select="."><xsl:copy-of
select="@*"/><xsl:apply-templates/></xsl:copy></xsl:template>
-<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>
+       <xsl:template match="*|comment()">
+               <xsl:copy select=".">
+                       <xsl:apply-templates select="@*"/>
+                       <xsl:apply-templates/>
+               </xsl:copy>
+       </xsl:template>
+       <xsl:template match="@*">
+               <xsl:attribute name="{name()}"><xsl:value-of
select="."/></xsl:attribute>
+       </xsl:template>
+       <xsl:template match="text()">
+               <xsl:value-of select="."/>
+       </xsl:template>
+       <xsl:template match="@href">
+               <xsl:attribute name="href"><xsl:value-of
select="perl:url_fix(.)"/></xsl:attribute>
+       </xsl:template>
+       <xsl:template match="@x:href">
+               <xsl:attribute name="x:href"><xsl:value-of
select="perl:url_fix(.)"/></xsl:attribute>
+       </xsl:template>
 </xsl:stylesheet>
 EOX
     my $stylesheet = XML::LibXSLT->parse_stylesheet($style_dom);
@@ -57,16 +91,10 @@
 
     my $result;
     my $input = $stylesheet->output_string($results);
-    my $host = $r->hostname;
-    $input =~ s{ href="/}{ href="http://$host/}g;
-    my $path = $r->document_root;
-    $input =~ s{ src="/}{ src="$path/}g;
-    $path = $r->uri;
-    $path =~ s{/+[^/]*$}{/};
-    $input =~ s{ href="(?!/|.{0,5}:)}{ href="http://$host$path}g;
+
     AxKit::Debug(8, "About to shell out to htmldoc - hope you have it
installed...");
     AxKit::Debug(10, $input);
-
run(['htmldoc','--quiet','--format','pdf13','--truetype','--size','a4','--co
lor','--charset','8859-15','--webpage',$r->dir_config->get('AxHtmlDocOptions
'),'-'],\$input,\$result);
+    run(['htmldoc','--quiet','--format','pdf13','--embedfonts',
'--size','a4','--color','--charset','8859-15','--webpage',$r->dir_config->ge
t('AxHtmlDocOptions'),'-'],\$input,\$result);
 
     if (substr($result,0,5) ne '%PDF-') {
         throw Apache::AxKit::Exception::Error(-text => 'htmldoc returned
error: '.$result);