Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped HTML characters in flexmark output #17

Closed
evanbergstrom opened this issue Jul 11, 2023 · 3 comments
Closed

Escaped HTML characters in flexmark output #17

evanbergstrom opened this issue Jul 11, 2023 · 3 comments

Comments

@evanbergstrom
Copy link

evanbergstrom commented Jul 11, 2023

I'm having a problem with the HTML output of flexmark-java being further processed and escaping characters in the HTML tags. I created a simple example class that shows the problem:

/**
 * This class is an example for using markdown in java doc.
 * ```java
 *  public void foo(bar b) {}
 * ```
 */
public class MDocletExample {
}

The block of HTML generated by javadoc for the comment is:

<div class="block">This class is an example for using markdown in java doc.&lt;pre&gt;&lt;code class="language-java"&gt;  public void foo(bar b) {}
&lt;/code&gt;&lt;/pre&gt;
</div>

It looks like something is taking the output of flexmark and escaping the < and > characters in the HTML. I'm using maven as the build tool. Here is the pom.xml for the example:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>mdoclet-example</artifactId>
  <version>0.1</version>
  <packaging>jar</packaging>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
              <source>17</source>
              <target>17</target>
              <debug>true</debug>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.4.1</version>
            <configuration>
              <doclet>org.jdrupes.mdoclet.MDoclet</doclet>
              <docletArtifacts>
                <docletArtifact>
                  <groupId>org.jdrupes.mdoclet</groupId>
                  <artifactId>doclet</artifactId>
                  <version>3.1.0</version>
                </docletArtifact>
                <docletArtifact>
                  <groupId>com.vladsch.flexmark</groupId>
                  <artifactId>flexmark-all</artifactId>
                  <version>0.64.8</version>
                </docletArtifact>
              </docletArtifacts>
              <additionalJOptions>
                <additionalJOption>-J--add-exports=jdk.javadoc/jdk.javadoc.internal.tool=ALL-UNNAMED</additionalJOption>
                <additionalJOption>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</additionalJOption>
              </additionalJOptions>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

@mnlipp
Copy link
Owner

mnlipp commented Jul 12, 2023

Sorry, but I cannot reproduce this. I've added your source in mdoclet/testfiles/test and run the test with JRE 17 and my "default test setup"

image

The result is (as to be expected):

image

Maybe something's wrong with your maven configuration, but as I don't know anything about maven, I cannot help you with that. Maybe compare the java invocation that all this maven magic results in.

Feel free to reopen this issue when you have any additional information.

@mnlipp mnlipp closed this as completed Jul 12, 2023
@evanbergstrom
Copy link
Author

I found the issue. The maven compiler plugin was running on JDK 17, the javadoc plugin was running on OpenJDK 20. Maybe there is a compatibility issue with the JDK 20 javadoc?

For anyone else having this problem, setting your JAVA_HOME to the same executable as the compiler plugin is using will fix it. I don't like having to mess around with environment variables, so I went with the approach of using the maven-toolchain-plugin, and that synchronized the version across all of the plugins while still making it easy to switch the versions around.

@mnlipp
Copy link
Owner

mnlipp commented Jul 12, 2023

I found the issue. The maven compiler plugin was running on JDK 17, the javadoc plugin was running on OpenJDK 20. Maybe there is a compatibility issue with the JDK 20 javadoc?

This wouldn't surprise me. Remember that I'm using a private API here and "hack my way around" (and the original authors have done many things to make this as difficult as possible, violating most rules of best practice OO design). I'll have a look at this again when the next LTS release comes out. Until then everybody should be aware that the doclet is supposed to be run with Java 17 -- anything else is pure luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants