Skip to content

Commit

Permalink
Wrap HTMLs in a template element (fix #ThoughtWorksInc/Binding.scala…
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Apr 30, 2023
1 parent 3c6b055 commit d627afe
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions html/src/main/scala/com/yang_bo/html/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,17 @@ package html {
val Varargs(argExprs) = args: @unchecked
val '{ StringContext($partsExpr: _*) } = stringContext: @unchecked
val Expr(partList) = partsExpr: @unchecked
val parts = partList.toIndexedSeq
val fragment = InterpolationParser.parseHtmlParts(
parts,
{ (message, arg) => report.error(message, argExprs(arg).asTerm.pos) }
)

// Wrap HTMLs in a template element, otherwise htmlunit cannot parse <tr> as a root element
val parts =
partList.toIndexedSeq.updated(0, s"<template>${partList.head}")
val rootNodes = InterpolationParser
.parseHtmlParts(
parts,
{ (message, arg) => report.error(message, argExprs(arg).asTerm.pos) }
)
.getFirstChild()
.getChildNodes()

// report.info(
// "arg:" + fragment.getFirstChild.getChildNodes
Expand All @@ -522,7 +528,6 @@ package html {
// .createLSSerializer()
// .writeToString(fragment)
// )
val rootNodes = fragment.getChildNodes
if rootNodes.getLength == 1 then
transformNode(rootNodes.item(0))(using argExprs.toIndexedSeq)
else transformNodeList(rootNodes)(using argExprs.toIndexedSeq)
Expand Down

0 comments on commit d627afe

Please sign in to comment.