Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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=(?:\\s+)?\"(.*)\">(?:\\s+)?(.*)</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"), "Anchor tags should be removed");
Assertions.assertFalse(generated.contains("</a>"), "Anchor tags should be removed");
Assertions.assertTrue(generated.contains("{@link https://github.com/vojtechhabarta/typescript-generator link}"), "Links should be converted to TSDoc");
Assertions.assertTrue(generated.contains("{@link https://github.com/vojtechhabarta/typescript-generator/wiki the wiki}"), "Links should be converted to TSDoc");
}
}

/**
Expand Down Expand Up @@ -217,4 +224,15 @@ 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=&#10; &quot;https://github.com/vojtechhabarta/typescript-generator/wiki&quot;&gt;&#10; 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=&#10; &quot;https://github.com/vojtechhabarta/typescript-generator/wiki&quot;&gt;&#10; 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