[Enhancement] enhance html spacing (#6617)

This commit is contained in:
ToobLac 2026-08-09 20:05:28 +08:00 committed by GitHub
parent ff459a5bc4
commit c149401cf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -454,7 +454,7 @@ public final class HTMLRenderer {
appendAutoLineBreak("\n\n");
}
case "hr" -> {
appendAutoLineBreak("\n");
appendAutoLineBreak("\n\n");
this.children.add(new Separator());
}
}
@ -512,16 +512,34 @@ public final class HTMLRenderer {
}
}
}
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();
break;
}
}
}
return this;
}
@ -537,6 +555,7 @@ public final class HTMLRenderer {
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) {