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

feat: ✨ convert Javadoc anchor tags to TSdoc links #888

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ private List<String> getComments(String dComments, List<TagInfo> tags) {
.replaceAll("\\s*<br />\\s*", nn)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data analyst can be reformed using a wiper

.replaceAll("\\s*<p>\\s*", nn)
.replaceAll("\\s*</p>\\s*", nn);
result.addAll(Utils.splitMultiline(replacedHtmlLines, true));
result.addAll(Utils.splitMultiline(convertAnchorToLink(replacedHtmlLines), true));
}
if (tags != null) {
for (TagInfo tag : tags) {
result.addAll(Utils.splitMultiline(tag.getName() + " " + tag.getText(), true));
result.addAll(Utils.splitMultiline(tag.getName() + " " + convertAnchorToLink(tag.getText()), true));
}
}
return result;
Expand All @@ -271,4 +271,14 @@ private static List<String> combineComments(List<String> firstComments, List<Str
return Utils.concat(firstComments, secondComments);
}

/**
* Replaces all anchor tags in the given string with TSdoc-style links.
*
* @param comment comment to convert
* @return comment with Javadoc anchor tags converted to TSdoc links
*/
private static String convertAnchorToLink(String comment) {
return comment.replaceAll("<a href=\"([^\"]+)\">([^<]+)</a>", "{@link $1 $2}");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public void testJavadoc() {
Assertions.assertTrue(!generated.contains("</p>"));
Assertions.assertTrue(generated.contains("Long\n * paragraph\n * \n * Second\n * paragraph"));
}
{
final String generated = new TypeScriptGenerator(settings).generateTypeScript(Input.from(ClassWithExternalLinks.class));
Assertions.assertFalse(generated.contains("<a"));
Assertions.assertFalse(generated.contains("</a>"));
Assertions.assertTrue(generated.contains("{@link https://github.com/vojtechhabarta/typescript-generator link}"));
Assertions.assertTrue(generated.contains("{@link https://github.com/vojtechhabarta/typescript-generator/wiki the wiki}"));
}
}

/**
Expand Down Expand Up @@ -217,4 +224,13 @@ public static class ClassWithBrElements {
public static class ClassWithPElements {
}

/**
* Documentation for ClassWithExternalLinks
*
* This sentence has a <a href="https://github.com/vojtechhabarta/typescript-generator">link</a>!
* @see <a href="https://github.com/vojtechhabarta/typescript-generator/wiki">the wiki</a>
*/
public static class ClassWithExternalLinks {
}

}
16 changes: 16 additions & 0 deletions typescript-generator-core/src/test/javadoc/test-javadoc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,14 @@
<class qualified="java.lang.Object"/>
<constructor name="ClassWithPElements" signature="()" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithPElements" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
</class>
<class name="JavadocTest.ClassWithExternalLinks" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithExternalLinks" scope="public" abstract="false" error="false" exception="false" externalizable="false" included="true" serializable="false">
<comment>Documentation for ClassWithExternalLinks

This sentence has a &lt;a href="https://github.com/vojtechhabarta/typescript-generator"&gt;link&lt;/a&gt;!</comment>
<tag name="@see" text="&lt;a href=&quot;https://github.com/vojtechhabarta/typescript-generator/wiki&quot;&gt;the wiki&lt;/a&gt;"/>
<class qualified="java.lang.Object"/>
<constructor name="ClassWithExternalLinks" signature="()" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithExternalLinks" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
</class>
<class name="JaxbTest" qualified="cz.habarta.typescript.generator.JaxbTest" scope="public" abstract="false" error="false" exception="false" externalizable="false" included="true" serializable="false">
<class qualified="java.lang.Object"/>
<constructor name="JaxbTest" signature="()" qualified="cz.habarta.typescript.generator.JaxbTest" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
Expand Down Expand Up @@ -8213,6 +8221,14 @@
<class qualified="java.lang.Object"/>
<constructor name="ClassWithPElements" signature="()" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithPElements" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
</class>
<class name="JavadocTest.ClassWithExternalLinks" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithExternalLinks" scope="public" abstract="false" error="false" exception="false" externalizable="false" included="true" serializable="false">
<comment>Documentation for ClassWithExternalLinks

This sentence has a &lt;a href="https://github.com/vojtechhabarta/typescript-generator"&gt;link&lt;/a&gt;!</comment>
<tag name="@see" text="&lt;a href=&quot;https://github.com/vojtechhabarta/typescript-generator/wiki&quot;&gt;the wiki&lt;/a&gt;"/>
<class qualified="java.lang.Object"/>
<constructor name="ClassWithExternalLinks" signature="()" qualified="cz.habarta.typescript.generator.JavadocTest.ClassWithExternalLinks" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
</class>
<class name="Jackson2PolymorphismTest" qualified="cz.habarta.typescript.generator.Jackson2PolymorphismTest" scope="public" abstract="false" error="false" exception="false" externalizable="false" included="true" serializable="false">
<class qualified="java.lang.Object"/>
<constructor name="Jackson2PolymorphismTest" signature="()" qualified="cz.habarta.typescript.generator.Jackson2PolymorphismTest" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
Expand Down