Skip to content

Commit

Permalink
javadoc inline tagをHTML化
Browse files Browse the repository at this point in the history
まず {@link} だけJavaScriptで暫定対応
importや同パッケージなどは解釈できない
  • Loading branch information
irof committed Jul 1, 2024
1 parent a870172 commit b68f5fd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
11 changes: 10 additions & 1 deletion jig-core/src/main/resources/templates/assets/jig.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ function sortTable(tableId, columnIndex) {
rows.forEach(function (row) {
tbody.appendChild(row);
});
}
}

function javadocToHtml(text) {
// linkタグの置き換え
text = text.replace(/{@link\s([^\s}]+?)}/g, '<a href="#$1">$1</a>');
text = text.replace(/{@link\s([^\s}]+?)\s+([^\s}]+?)}/g, '<a href="#$1">$2</a>');
return text;
}

Array.from(document.getElementsByClassName("javadoc")).forEach(x => x.innerHTML = javadocToHtml(x.innerHTML))
2 changes: 1 addition & 1 deletion jig-core/src/main/resources/templates/enum.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2><a th:name="${item.fqn()}" th:text="${item.label()}">XXXクラス</a></h2>
<div class="fully-qualified-name" th:text="${item.fqn()}">org.dddjava.jig.package.Class</div>

<th:block th:with="description=${item.description()}">
<section class="markdown" th:if="${description.hasContent()}" th:utext="${description.content()}">
<section class="markdown javadoc" th:if="${description.hasContent()}" th:utext="${description.content()}">
クラスのJavadocコメントが表示されます
</section>
</th:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2><a th:name="${item.fqn()}" th:text="${item.label()}">XXXパッケージ</a><
<small class="fully-qualified-name" th:text="${item.fqn()}">org.dddjava.jig.package</small>

<th:block th:with="description=${item.description()}">
<section class="markdown" th:if="${description.hasContent()}" th:utext="${description.content()}">
<section class="markdown javadoc" th:if="${description.hasContent()}" th:utext="${description.content()}">
package-infoのJavadocコメントが表示されます

- ここではMarkdownがmarkedによりHTML出力されます。
Expand Down
4 changes: 2 additions & 2 deletions jig-core/src/main/resources/templates/fragment-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2><a th:name="${item.fqn()}" th:text="${item.label()}" th:classappend="${item.
<div class="fully-qualified-name" th:text="${item.fqn()}">org.dddjava.jig.package.Class</div>

<th:block th:with="description=${item.description()}">
<section class="markdown" th:if="${description.hasContent()}" th:utext="${description.content()}">クラスのJavadocコメントが表示されます</section>
<section class="markdown javadoc" th:if="${description.hasContent()}" th:utext="${description.content()}">クラスのJavadocコメントが表示されます</section>
</th:block>

<section th:if="${categoriesMap.containsKey(item.identifier())}"
Expand Down Expand Up @@ -67,7 +67,7 @@ <h2>フラグメント</h2>
th:href="${'#' + arg.fullQualifiedName()}" th:text="${#jig.labelText(arg)}">xxx</a>
</td>
<td th:utext="${#jig.methodReturnRawText(method.declaration().methodReturn())}">xxxx</td>
<td class="markdown" th:utext="${method.description().content()}">javadoc comment</td>
<td class="markdown javadoc" th:utext="${method.description().content()}">javadoc comment</td>
</tr>
</table>
</th:block>
Expand Down
2 changes: 1 addition & 1 deletion jig-core/src/main/resources/templates/term.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr th:each="term : ${terms.list()}">
<td th:text="${term.identifier.simpleText()}" class="term">ClassName</td>
<td th:text="${term.title()}" class="term">用語の和名が表示されます</td>
<td th:utext="${term.description()}" class="markdown">ここには **マークダウン** での説明が記述されます。</td>
<td th:utext="${term.description()}" class="markdown javadoc">ここには **マークダウン** での説明が記述されます。</td>
<td th:text="${term.termKind()}" class="kind">クラス</td>
<td th:text="${term.identifier.asText()}" class="identifier">this.is.full.ClassName</td>
</tr>
Expand Down

0 comments on commit b68f5fd

Please sign in to comment.