From 52a86fffc7392ffcf29443b46044027b6470046d Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Tue, 23 Apr 2024 09:00:31 +0300 Subject: [PATCH] Emit literals as `` instead of using "`" Using `` works consistently inside different documentation html tags fix #104 --- .../tsdefs/doclet/TsDocTreeVisitor.java | 7 +-- .../tests/tsdocs/doclet/DocletTest.java | 5 ++ .../links/issue104/JsTypeWithCodeTagDocs.java | 58 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/issue104/JsTypeWithCodeTagDocs.java diff --git a/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java b/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java index 0bd80c7..25a1492 100644 --- a/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java +++ b/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java @@ -139,12 +139,7 @@ public String visitDocComment(DocCommentTree node, Element element) { @Override public String visitLiteral(LiteralTree node, Element element) { if (nonNull(node.getBody())) { - String body = node.getBody().getBody(); - String wrap = "`"; - if (body.contains(System.lineSeparator())) { - wrap = "```"; - } - return wrap + node.getBody().getBody() + wrap; + return "" + node.getBody().getBody() + ""; } return super.visitLiteral(node, element); } diff --git a/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/DocletTest.java b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/DocletTest.java index c71570e..f675b85 100644 --- a/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/DocletTest.java +++ b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/DocletTest.java @@ -72,4 +72,9 @@ public void testMethodsLinks() throws IOException { public void testIssue99() throws IOException { testDocs("links.issue99"); } + + @Test + public void testIssue104() throws IOException { + testDocs("links.issue104"); + } } diff --git a/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/issue104/JsTypeWithCodeTagDocs.java b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/issue104/JsTypeWithCodeTagDocs.java new file mode 100644 index 0000000..7b98f1f --- /dev/null +++ b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/issue104/JsTypeWithCodeTagDocs.java @@ -0,0 +1,58 @@ +/* + * Copyright © 2024 Vertispan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.vertispan.tsdefs.tests.tsdocs.doclet.links.issue104; + +import jsinterop.annotations.JsType; + +/** + * This is a JsType to test {@code code snippet} in docs example {@code code snippet a} in + * tags and we also test + * + * + * + * {@code code snippet c} + */ +@JsType +public class JsTypeWithCodeTagDocs { + + /** + * This is a field to test {@code code snippet} in docs example {@code code snippet a} in + * tags and we also test + * + * + * + * {@code code snippet c} + */ + public String field; + + /** + * This is a method to test {@code code snippet} in docs example {@code code snippet a} in + * tags and we also test + * + * + * + * {@code code snippet c} + */ + public void doSomething() { + return; + } +}