summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-06-23 15:54:52 +0200
committerLaurenz <laurmaedje@gmail.com>2025-06-23 15:59:22 +0200
commitbf8ef2a4a5ffa9c30fce9fc254ffcf982634e4c6 (patch)
treeead60969ba9f14d0c06de5a0ba5327ae54b565b1 /tests
parentc2e2fd99f69665e2361a1129dd04121a5b2c61a2 (diff)
Properly handle raw text elements
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/html/html-escapable-raw-text-contains-closing-tag.html8
-rw-r--r--tests/ref/html/html-script.html21
-rw-r--r--tests/ref/html/html-style.html14
-rw-r--r--tests/suite/html/syntax.typ51
4 files changed, 94 insertions, 0 deletions
diff --git a/tests/ref/html/html-escapable-raw-text-contains-closing-tag.html b/tests/ref/html/html-escapable-raw-text-contains-closing-tag.html
new file mode 100644
index 00000000..9e0b9643
--- /dev/null
+++ b/tests/ref/html/html-escapable-raw-text-contains-closing-tag.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ </head>
+ <body><textarea>hello &lt;/textarea></textarea></body>
+</html>
diff --git a/tests/ref/html/html-script.html b/tests/ref/html/html-script.html
new file mode 100644
index 00000000..81b74765
--- /dev/null
+++ b/tests/ref/html/html-script.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ </head>
+ <body>
+ <script>
+ const x = 1
+ const y = 2
+ console.log(x < y, Math.max(1, 2))
+ </script>
+ <script>
+console.log(`Hello
+World`)
+ </script>
+ <script type="text/python">x = 1
+y = 2
+print(x < y, max(x, y))</script>
+ </body>
+</html>
diff --git a/tests/ref/html/html-style.html b/tests/ref/html/html-style.html
new file mode 100644
index 00000000..c8d558bc
--- /dev/null
+++ b/tests/ref/html/html-style.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ </head>
+ <body>
+ <style>
+ body {
+ text: red;
+ }
+ </style>
+ </body>
+</html>
diff --git a/tests/suite/html/syntax.typ b/tests/suite/html/syntax.typ
index fb5caf3b..eb1c8699 100644
--- a/tests/suite/html/syntax.typ
+++ b/tests/suite/html/syntax.typ
@@ -10,3 +10,54 @@
#html.pre("hello")
#html.pre("\nhello")
#html.pre("\n\nhello")
+
+--- html-script html ---
+// This should be pretty and indented.
+#html.script(
+ ```js
+ const x = 1
+ const y = 2
+ console.log(x < y, Math.max(1, 2))
+ ```.text,
+)
+
+// This should have extra newlines, but no indent because of the multiline
+// string literal.
+#html.script("console.log(`Hello\nWorld`)")
+
+// This should be untouched.
+#html.script(
+ type: "text/python",
+ ```py
+ x = 1
+ y = 2
+ print(x < y, max(x, y))
+ ```.text,
+)
+
+--- html-style html ---
+// This should be pretty and indented.
+#html.style(
+ ```css
+ body {
+ text: red;
+ }
+ ```.text,
+)
+
+--- html-raw-text-contains-elem html ---
+// Error: 14-32 HTML raw text element cannot have non-text children
+#html.script(html.strong[Hello])
+
+--- html-raw-text-contains-frame html ---
+// Error: 2-29 HTML raw text element cannot have non-text children
+#html.script(html.frame[Ok])
+
+--- html-raw-text-contains-closing-tag html ---
+// Error: 2-32 HTML raw text element cannot contain its own closing tag
+// Hint: 2-32 the sequence `</SCRiPT` appears in the raw text
+#html.script("hello </SCRiPT ")
+
+--- html-escapable-raw-text-contains-closing-tag html ---
+// This is okay because we escape it.
+#html.textarea("hello </textarea>")