Skip to content

Commit 95ee55c

Browse files
committed
Document that /> is an unnecessary talisman in HTML
#215
1 parent cd4f7d3 commit 95ee55c

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

c-api/include/lol_html.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,15 @@ int lol_html_element_tag_name_set(
523523
size_t name_len
524524
);
525525

526-
// Whether the element is explicitly self-closing, e.g. `<foo />`.
526+
// Whether the tag syntactically ends with `/>`. In HTML content this is purely a decorative, unnecessary, and has no effect of any kind.
527+
//
528+
// The `/>` syntax only affects parsing of elements in foreign content (SVG and MathML).
529+
// It will never close any HTML tags that aren't already defined as void in HTML.
530+
//
531+
// This function only reports the parsed syntax, and will not report which elements are actually void in HTML.
532+
// Use `lol_html_element_can_have_content` to check if the element is non-void.
533+
//
534+
// If the `/` is part of an unquoted attribute, it's not parsed as the self-closing syntax.
527535
bool lol_html_element_is_self_closing(
528536
lol_html_element_t *element
529537
);

src/rewritable_units/element.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
121121
}
122122

123123
/// Sets the tag name of the element.
124+
///
125+
/// The new tag name must be in the same namespace, have the same content model, and be valid in its location.
126+
/// Otherwise change of the tag name may cause the resulting document to be parsed in an unexpected way,
127+
/// out of sync with this library.
124128
#[inline]
125129
pub fn set_tag_name(&mut self, name: &str) -> Result<(), TagNameError> {
126130
let name = self.tag_name_bytes_from_str(name)?;
@@ -134,16 +138,31 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
134138
Ok(())
135139
}
136140

137-
/// Whether the element is explicitly self-closing, e.g. `<foo />`.
141+
/// Whether the tag syntactically ends with `/>`. In HTML content this is purely a decorative, unnecessary, and has no effect of any kind.
142+
///
143+
/// The `/>` syntax only affects parsing of elements in foreign content (SVG and MathML).
144+
/// It will never close any HTML tags that aren't already defined as [void][spec] in HTML.
145+
///
146+
/// This function only reports the parsed syntax, and will not report which elements are actually void in HTML.
147+
/// Use [`can_have_content()`][Self::can_have_content] to check if the element is non-void.
148+
///
149+
/// [spec]: https://html.spec.whatwg.org/multipage/syntax.html#start-tags
150+
///
151+
/// If the `/` is part of an unquoted attribute, it's not parsed as the self-closing syntax.
138152
#[inline]
139153
#[must_use]
140154
pub fn is_self_closing(&self) -> bool {
141155
self.start_tag.self_closing()
142156
}
143157

144-
/// Whether the element can have inner content. Returns `true` unless the element is an [HTML void
145-
/// element](https://html.spec.whatwg.org/multipage/syntax.html#void-elements) or has a
146-
/// self-closing tag (eg, `<foo />`).
158+
/// Whether the element can have inner content.
159+
///
160+
/// Returns `true` if the element isn't a [void element in HTML][void],
161+
/// or is in **foreign content** and doesn't have a self-closing tag (eg, `<svg />`).
162+
///
163+
/// [void]: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
164+
///
165+
/// Note that the self-closing syntax has no effect in HTML content.
147166
#[inline]
148167
#[must_use]
149168
pub fn can_have_content(&self) -> bool {

src/rewritable_units/tokens/start_tag.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,16 @@ impl<'i> StartTag<'i> {
102102
}
103103
}
104104

105-
/// Whether the tag is explicitly self-closing, e.g. `<foo />`.
105+
/// Whether the tag syntactically ends with `/>`. In HTML content this is purely a decorative, unnecessary, and has no effect of any kind.
106+
///
107+
/// The `/>` syntax only affects parsing of elements in foreign content (SVG and MathML).
108+
/// It will never close any HTML tags that aren't already defined as [void](spec) in HTML.
109+
///
110+
/// This function only reports the parsed syntax, and will not report which elements are actually void in HTML.
111+
///
112+
/// [spec]: https://html.spec.whatwg.org/multipage/syntax.html#start-tags
113+
///
114+
/// If the `/` is part of an unquoted attribute, it's not parsed as the self-closing syntax.
106115
#[inline]
107116
pub fn self_closing(&self) -> bool {
108117
self.self_closing

0 commit comments

Comments
 (0)