Skip to content

Commit

Permalink
rx-html (feature): Support rendering RawHtml (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial authored Mar 5, 2025
1 parent 4d64afb commit ab949e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ object DOMRenderer extends LogSupport {
val textNode = newTextNode(s)
node.mountHere(textNode, anchor)
Cancelable.empty
case r: RawHtml =>
val domNode = dom.document.createElement("span")
domNode.innerHTML = r.html
// Extract the inner node
domNode.childNodes.headOption.foreach { n =>
node.mountHere(n, anchor)
}
Cancelable.empty
case EntityRef(entityName) =>
// Wrap entity ref with a span tag.
// This is a workaround if the text is inserted in the middle of text element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ class HtmlRenderingTest extends AirSpec {
val d = div("1.23", EntityRef("amp"), "0.5")
render(d).contains("&") shouldBe true
}

test("raw html") {
val d = div(RawHtml("<b>hello</b>"))
render(d) shouldBe "<div><b>hello</b></div>"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class HtmlEventHandlerOf[E](name: String, namespace: Namespace = Namespace.xhtml

case class EntityRef(ref: String) extends HtmlNode

case class RawHtml(html: String) extends HtmlNode

// Used for properly embedding namespaces to DOM. For example, for rendering SVG elements,
// Namespace.svg must be set to DOM elements. If not, the SVG elements will not be rendered in the web browsers.
case class Namespace(uri: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
package wvlet.airframe.rx.html

import wvlet.airframe.rx.html.RxEmbedding.*
import wvlet.airframe.rx.{Cancelable, Rx}
import wvlet.log.LogSupport
import wvlet.airframe.rx.html.RxEmbedding.*

/**
*/
Expand Down

0 comments on commit ab949e2

Please # to comment.