Skip to content
Open
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
37 changes: 28 additions & 9 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/HTMLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public HTMLRenderer appendNode(Node node) {
appendAutoLineBreak("\n\n");
}
case "hr" -> {
appendAutoLineBreak("\n");
appendAutoLineBreak("\n\n");
this.children.add(new Separator());
}
}
Expand Down Expand Up @@ -512,16 +512,34 @@ public HTMLRenderer mergeLineBreaks() {
}
}
}
int size = children.size();
for (int i = 0; i < size; i++) {
var child = children.get(i);
if (child instanceof AutoLineBreak || (child instanceof Text txt && isSpacing(txt.getText()))) {
// do nothing
} else {
children.subList(0, i).clear();
break;

{
// Remove empty lines at the beginning
int size = children.size();
for (int i = 0; i < size; i++) {
var child = children.get(i);
if (child instanceof AutoLineBreak || child instanceof Text txt && isSpacing(txt.getText())) {
// NO-OP
} else {
this.children.subList(0, i).clear();
break;
}
}
}
{
// Remove empty lines and spaces at the end
int size = children.size();
for (int i = size - 1; i > -1; i--) {
var child = children.get(i);
if (child instanceof AutoLineBreak || child instanceof Text txt && isSpacing(txt.getText())) {
// NO-OP
} else {
this.children.subList(i + 1, size).clear();
Comment on lines +534 to +537

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 应清理最后一个文本节点内部的尾随空白

对于 <p>x </p> 这样的内容,Jsoup 会生成 Text("x "),后面再跟一个 AutoLineBreak。由于 isSpacing("x ") 返回 false,当前循环只会删除换行节点,却保留 x 后面的空格。这样不仅未彻底清理尾随空白,还可能影响 TextFlow 的尺寸计算和自动换行。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

我认为这不应该处理。照这么说,一个 Text 节点内如果包含了一堆连起来的换行符岂不是也得找出来?既然空格是节点的一部分就不应该处理

break;
}
}
}

return this;
}

Expand All @@ -537,6 +555,7 @@ public TextFlow render() {
InvalidationListener listener = __ -> img.setFitWidth(Math.min(textFlow.getWidth() * 0.9, img.getImage() == null ? 0D : img.getImage().getWidth()));
textFlow.widthProperty().addListener(listener);
img.imageProperty().addListener(listener);
listener.invalidated(null);
} else if (node instanceof TableView<?> table) {
table.prefWidthProperty().bind(textFlow.widthProperty().multiply(0.8));
} else if (node instanceof CodeFlow codeFlow) {
Expand Down