Skip to content

Commit 4ef529b

Browse files
committed
fix(markdown): correct javadoc vars no-op + htmlToMarkdown attribute tags
1 parent ab6417f commit 4ef529b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

easydoc-xhtml/src/main/java/io/github/easy4j/doc/xhtml/markdown/EasyMarkdown.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static WordprocessingMLPackage markdownToDocx(String markdown) throws Exc
2424
return markdownToDocx(markdown, null);
2525
}
2626

27-
/** Markdown → docx(支持 ${var} 占位符替换——MD 内容渲染后由 HTML 管线处理)。 */
27+
/** Markdown → docx。variables 参数当前未生效(WordprocessingMLHtmlTemplate 暂不支持 HTML 变量替换);传入 null 即可。 */
2828
public static WordprocessingMLPackage markdownToDocx(String markdown,
2929
Map<String, Object> vars) throws Exception {
3030
String html = MarkdownConverter.mdToHtml(markdown);

easydoc-xhtml/src/main/java/io/github/easy4j/doc/xhtml/markdown/MarkdownConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public static String htmlToMarkdown(String html) {
4848
.replaceAll("(?i)</h2>", "\n")
4949
.replaceAll("(?i)<h3[^>]*>", "\n### ")
5050
.replaceAll("(?i)</h3>", "\n")
51-
.replaceAll("(?i)<strong>", "**").replaceAll("(?i)</strong>", "**")
52-
.replaceAll("(?i)<em>", "*").replaceAll("(?i)</em>", "*")
53-
.replaceAll("(?i)<li>", "- ").replaceAll("(?i)</li>", "\n")
51+
.replaceAll("(?i)<strong[^>]*>", "**").replaceAll("(?i)</strong>", "**")
52+
.replaceAll("(?i)<em[^>]*>", "*").replaceAll("(?i)</em>", "*")
53+
.replaceAll("(?i)<li[^>]*>", "- ").replaceAll("(?i)</li>", "\n")
5454
.replaceAll("(?i)<p[^>]*>", "\n").replaceAll("(?i)</p>", "\n")
5555
.replaceAll("(?i)<td[^>]*>", " | ").replaceAll("(?i)</td>", "")
5656
.replaceAll("(?i)</tr>", "\n")

easydoc-xhtml/src/test/java/io/github/easy4j/doc/xhtml/markdown/MarkdownConverterTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ void mdToHtmlConvertsCodeBlockAndList() {
2727
assertTrue(html.contains("<pre>"), "code block must render to <pre>");
2828
assertTrue(html.contains("<li>item1</li>"), "list item must render");
2929
}
30+
31+
@Test
32+
void htmlToMarkdownHandlesTagsWithAttributes() {
33+
String md = MarkdownConverter.htmlToMarkdown(
34+
"<strong class=\"x\">bold</strong> and <li class=\"y\">item</li>");
35+
assertTrue(md.contains("**bold**"), "strong with attribute must become **bold**");
36+
assertTrue(md.contains("- item"), "li with attribute must become list item");
37+
}
3038
}

0 commit comments

Comments
 (0)