admin管理员组

文章数量:1122832

I try to use the maven site Plugin to write Documentation for my Program. But when I try to link links that contain special chars like '(' it escapes them in the wrong format: '.28' but I would expect '%28'.
I tried it with markdown, atp, xdoc and xhtml source files. I also tried to use older Versions of the site plugin, like 3.12.1 and 3.7.1.
Here is my xhtml input:

<!DOCTYPE html>
<html xmlns="; lang="en">
  <body>
  Test
  <a href="./apidocs/com.example.example/com/example/example/Test.html#function(java.lang.String)" >Link</a>
  </body>
</html>

Here is my pom.xml:

<project xmlns=".0.0"
    xmlns:xsi=";
    xsi:schemaLocation=".0.0 .0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.example</groupId>
    <artifactId>example</artifactId>
    <version>0.8.4</version>
    <name>Example</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mavenpiler.source>17</mavenpiler.source>
        <mavenpiler.target>17</mavenpiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
        </plugins>
    </reporting>
</project>

And this is the (truncated) generated html file:

<!DOCTYPE html>
<!--
 | Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xhtml/test.xhtml at 2025-01-06
 | Rendered using Apache Maven Fluido Skin 2.0.1
-->
<html xmlns="; lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" />
    <link rel="stylesheet" href="./css/apache-maven-fluido-2.0.1.min.css" />
    <link rel="stylesheet" href="./css/site.css" />
    <link rel="stylesheet" href="./css/print.css" media="print" />
    <script src="./js/apache-maven-fluido-2.0.1.min.js"></script>
  </head>
  <body>
    <div class="container-fluid container-fluid-top">
      <div class="row-fluid">
        <main id="bodyColumn" class="span10">
  Test
  <a href="./apidocs/com.example.example/com/example/example/Test.html#function.28java.lang.String.29">Link</a>
        </main>
      </div>
    </div>
  </body>
</html>

I try to use the maven site Plugin to write Documentation for my Program. But when I try to link links that contain special chars like '(' it escapes them in the wrong format: '.28' but I would expect '%28'.
I tried it with markdown, atp, xdoc and xhtml source files. I also tried to use older Versions of the site plugin, like 3.12.1 and 3.7.1.
Here is my xhtml input:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <body>
  Test
  <a href="./apidocs/com.example.example/com/example/example/Test.html#function(java.lang.String)" >Link</a>
  </body>
</html>

Here is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.example</groupId>
    <artifactId>example</artifactId>
    <version>0.8.4</version>
    <name>Example</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
        </plugins>
    </reporting>
</project>

And this is the (truncated) generated html file:

<!DOCTYPE html>
<!--
 | Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xhtml/test.xhtml at 2025-01-06
 | Rendered using Apache Maven Fluido Skin 2.0.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" />
    <link rel="stylesheet" href="./css/apache-maven-fluido-2.0.1.min.css" />
    <link rel="stylesheet" href="./css/site.css" />
    <link rel="stylesheet" href="./css/print.css" media="print" />
    <script src="./js/apache-maven-fluido-2.0.1.min.js"></script>
  </head>
  <body>
    <div class="container-fluid container-fluid-top">
      <div class="row-fluid">
        <main id="bodyColumn" class="span10">
  Test
  <a href="./apidocs/com.example.example/com/example/example/Test.html#function.28java.lang.String.29">Link</a>
        </main>
      </div>
    </div>
  </body>
</html>
Share Improve this question asked yesterday ASDFGamerASDFGamer 33 bronze badges 7
  • Seems to be a Doxia rewriting thing. Perhaps help it by urlencoding the hash first? – mplungjan Commented yesterday
  • Yeah, I suspect that it has to do something with that. I also tried it by urlencoding, but if i write it like %28 it escaped the '%' (also with a '.'). And I don't know of another way to encode it first. – ASDFGamer Commented yesterday
  • I don't think that this is a duplicate because the other question was that it didn't add a dot. And i'm using a newer Version than the one that was assumed in the answer. – ASDFGamer Commented yesterday
  • It seems the version does not matter then. Doxia does not like () in urls - which is undestandable. – mplungjan Commented yesterday
  • Ok, thanks. Then i will work around that bug with a script that replaces the wrong lines. – ASDFGamer Commented yesterday
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I am now using a workaround, that fixes the Problem fully as far as I can see. I have added the exec-maven-plugin as a build plugin to the post-site phase to execute a script.

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>3.5.0</version>
    <executions>
        <execution>
            <id>Fix Site generated Links</id>
            <phase>post-site</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>${basedir}/src/site/fixLinks.sh</executable>
    </configuration>
</plugin>

That script contains the follwing sed command to fix the escapes: sed -i 's/.([0123456789ABCDEF][0123456789ABCDEF])/%\1/g' *.html
I'm not using \d in the sed command, because that isn't supported by the bash that comes bundled with git on windows.
Here is the full script:

#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
cd ../../target/site
sed -i 's/\.\([0123456789ABCDEF][0123456789ABCDEF]\)/%\1/g' *.html

本文标签: htmlInvalid Escape Sequences in Link generated by Maven SiteStack Overflow