diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-06-24 17:52:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-24 15:52:15 +0000 |
| commit | f2f527c451b1b05b393af99b89c528aadb203ce6 (patch) | |
| tree | bad5d6f5de768e1d04680267618b0cf78fec64a5 | |
| parent | 9e3c1199edddc0422d34a266681d2efe1babd0c1 (diff) | |
Also fix encoding of `<textarea>` (#6497)
| -rw-r--r-- | crates/typst-html/src/encode.rs | 2 | ||||
| -rw-r--r-- | tests/ref/html/html-textarea-starting-with-newline.html | 10 | ||||
| -rw-r--r-- | tests/suite/html/syntax.typ | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/crates/typst-html/src/encode.rs b/crates/typst-html/src/encode.rs index adcb6e03..9c793836 100644 --- a/crates/typst-html/src/encode.rs +++ b/crates/typst-html/src/encode.rs @@ -113,7 +113,7 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> { /// Encodes the children of an element. fn write_children(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> { // See HTML spec ยง 13.1.2.5. - if element.tag == tag::pre && starts_with_newline(element) { + if matches!(element.tag, tag::pre | tag::textarea) && starts_with_newline(element) { w.buf.push('\n'); } diff --git a/tests/ref/html/html-textarea-starting-with-newline.html b/tests/ref/html/html-textarea-starting-with-newline.html new file mode 100644 index 00000000..9c234037 --- /dev/null +++ b/tests/ref/html/html-textarea-starting-with-newline.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + </head> + <body><textarea> + +enter</textarea></body> +</html> diff --git a/tests/suite/html/syntax.typ b/tests/suite/html/syntax.typ index eb1c8699..4bda0c68 100644 --- a/tests/suite/html/syntax.typ +++ b/tests/suite/html/syntax.typ @@ -11,6 +11,9 @@ #html.pre("\nhello") #html.pre("\n\nhello") +--- html-textarea-starting-with-newline html --- +#html.textarea("\nenter") + --- html-script html --- // This should be pretty and indented. #html.script( |
