mirror of
https://github.com/typst/typst
synced 2025-06-22 21:32:52 +08:00
Encode empty attributes with shorthand syntax
This commit is contained in:
parent
f364b3c323
commit
fee6844045
@ -69,16 +69,21 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
|
||||
for (attr, value) in &element.attrs.0 {
|
||||
w.buf.push(' ');
|
||||
w.buf.push_str(&attr.resolve());
|
||||
w.buf.push('=');
|
||||
w.buf.push('"');
|
||||
for c in value.chars() {
|
||||
if charsets::is_valid_in_attribute_value(c) {
|
||||
w.buf.push(c);
|
||||
} else {
|
||||
write_escape(w, c).at(element.span)?;
|
||||
|
||||
// If the string is empty, we can use shorthand syntax.
|
||||
// `<elem attr="">..</div` is equivalent to `<elem attr>..</div>`
|
||||
if !value.is_empty() {
|
||||
w.buf.push('=');
|
||||
w.buf.push('"');
|
||||
for c in value.chars() {
|
||||
if charsets::is_valid_in_attribute_value(c) {
|
||||
w.buf.push(c);
|
||||
} else {
|
||||
write_escape(w, c).at(element.span)?;
|
||||
}
|
||||
}
|
||||
w.buf.push('"');
|
||||
}
|
||||
w.buf.push('"');
|
||||
}
|
||||
|
||||
w.buf.push('>');
|
||||
|
Loading…
x
Reference in New Issue
Block a user