Skip to content

Commit

Permalink
Added trivial support for SVG via Html component
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Dec 21, 2022
1 parent be4572d commit da82d35
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions flow-server/src/main/java/com/vaadin/flow/component/Html.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,30 @@ private void setOuterHtml(String outerHtml, boolean update) {
}

org.jsoup.nodes.Element root = doc.body().child(0);
Attributes attrs = root.attributes();
if (root.nodeName().equals("svg")) {
// SVG can't be handled like normal elements on the
// client side due to different namespace, wrap in div
Component.setElement(this, new Element("div"));
getElement().setProperty("innerHTML", outerHtml);
} else {

if (!update) {
Component.setElement(this, new Element(root.tagName()));
}
attrs.forEach(this::setAttribute);
Attributes attrs = root.attributes();

if (!update) {
Component.setElement(this, new Element(root.tagName()));
}
attrs.forEach(this::setAttribute);

if (update && !root.tagName().equals(getElement().getTag())) {
throw new IllegalStateException("Existing root tag '"
+ getElement().getTag() + "' can't be changed to '"
+ root.tagName() + "'");
}

if (update && !root.tagName().equals(getElement().getTag())) {
throw new IllegalStateException(
"Existing root tag '" + getElement().getTag()
+ "' can't be changed to '" + root.tagName() + "'");
doc.outputSettings().prettyPrint(false);
setInnerHtml(root.html());
}

doc.outputSettings().prettyPrint(false);
setInnerHtml(root.html());
}

private void setAttribute(Attribute attribute) {
Expand Down

0 comments on commit da82d35

Please sign in to comment.