Reputation: 3
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>
Upvotes: 0
Views: 26
Reputation: 3
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
Upvotes: 0