Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verbatim HTML - support <script> as root element #669

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/laika/ast/html/elements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ case class HTMLScriptElement(
attributes: List[HTMLAttribute],
content: String,
options: Options = Options.empty
) extends HTMLSpan with TextContainer {
) extends HTMLSpan with TextContainer with Block {
type Self = HTMLScriptElement
def withOptions(options: Options): HTMLScriptElement = copy(options = options)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,6 @@ private[laika] object HTMLParsers {
"<" ~> (htmlComment | htmlEmptyElement | htmlStartTag) <~ wsEol ~ blankLine

lazy val htmlBlockFragment: BlockParserBuilder =
BlockParserBuilder.standalone(htmlBlock | htmlBlockElement).rootOnly // TODO - keep separate
BlockParserBuilder.standalone("<" ~> htmlScriptElement | htmlBlock | htmlBlockElement).rootOnly

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ class HTMLBlockParserSpec extends FunSuite
run(input, p("aaa"), html.HTMLBlock(outer), p("bbb"))
}

test("recognize a script tag as a root element") {
val input = """aaa
|
|<script type="text/javascript" defer>
| var x = [1, 2, 3];
| var y = 'foo';
|</script>
|
|bbb""".stripMargin
val script = HTMLScriptElement(
List(
HTMLAttribute("type", List(Text("text/javascript")), Some('"')),
HTMLAttribute("defer", List(), None)
),
"\n var x = [1, 2, 3];\n var y = 'foo';\n"
)
run(input, p("aaa"), script, p("bbb"))
}

test("ignore elements which are not listed as block-level elements") {
val input = """aaa
|
Expand Down
Loading