html_sys/
lib.rs

1pub mod edits;
2pub mod embedded;
3pub mod forms;
4pub mod interactive;
5pub mod metadata;
6pub mod root;
7pub mod scripting;
8pub mod sections;
9pub mod tables;
10pub mod text;
11/// Render an element to a writer.
12pub trait RenderElement {
13    /// Write the opening tag to a writer.
14    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result;
15    /// Write the closing tag to a writer, if one is available.
16    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result;
17}
18/// Container for `data-*` attributes.
19#[derive(Debug, Clone, PartialEq, Default)]
20pub struct DataMap {
21    map: std::collections::HashMap<
22        std::borrow::Cow<'static, str>,
23        std::borrow::Cow<'static, str>,
24    >,
25}
26impl std::ops::Deref for DataMap {
27    type Target = std::collections::HashMap<
28        std::borrow::Cow<'static, str>,
29        std::borrow::Cow<'static, str>,
30    >;
31    fn deref(&self) -> &Self::Target {
32        &self.map
33    }
34}
35impl std::ops::DerefMut for DataMap {
36    fn deref_mut(&mut self) -> &mut Self::Target {
37        &mut self.map
38    }
39}
40impl std::fmt::Display for DataMap {
41    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        for (key, value) in self.map.iter() {
43            write!(writer, r#" data-{key}="{value}""#)?;
44        }
45        Ok(())
46    }
47}
48/// The "global attributes" struct
49#[derive(Debug, Clone, PartialEq, Default)]
50pub struct GlobalAttributes {
51    /// Provides a hint for generating a keyboard shortcut for the current element
52    pub access_key: std::option::Option<std::borrow::Cow<'static, str>>,
53    /// Controls whether and how text input is automatically capitalized as it is entered/edited by the user
54    pub auto_capitalize: std::option::Option<std::borrow::Cow<'static, str>>,
55    /// Indicates that an element should be focused on page load, or when the <dialog> that it is part of is displayed
56    pub autofocus: bool,
57    /// A space-separated list of the case-sensitive classes of the element
58    pub class: std::option::Option<std::borrow::Cow<'static, str>>,
59    /// Indicates if the element should be editable by the user
60    pub content_editable: std::option::Option<std::borrow::Cow<'static, str>>,
61    /// Indicates the directionality of the element's text
62    pub direction: std::option::Option<std::borrow::Cow<'static, str>>,
63    /// Indicates whether the element can be dragged, either with native browser behavior or the HTML Drag and Drop API.
64    pub draggable: bool,
65    /// Defines what action label (or icon) to present for the enter key on virtual keyboards
66    pub enter_key_hint: std::option::Option<std::borrow::Cow<'static, str>>,
67    /// The exportparts global attribute allows you to select and style elements existing in nested shadow trees, by exporting their part names
68    pub export_parts: std::option::Option<std::borrow::Cow<'static, str>>,
69    /// Indicates that the browser should not render the contents of the element
70    pub hidden: std::option::Option<std::borrow::Cow<'static, str>>,
71    /// Defines an identifier (ID) which must be unique in the whole document
72    pub id: std::option::Option<std::borrow::Cow<'static, str>>,
73    /// indicating that the browser will ignore the element
74    pub inert: bool,
75    /// hints at the type of data that might be entered by the user while editing the element or its contents
76    pub input_mode: std::option::Option<std::borrow::Cow<'static, str>>,
77    /// allows you to specify that a standard HTML element should behave like a defined custom built-in element
78    pub is_: std::option::Option<std::borrow::Cow<'static, str>>,
79    /// The itemid global attribute provides microdata in the form of a unique, global identifier of an item
80    pub item_id: std::option::Option<std::borrow::Cow<'static, str>>,
81    /// The itemprop global attribute is used to add properties to an item
82    pub item_prop: std::option::Option<std::borrow::Cow<'static, str>>,
83    /// Properties that are not descendants of an element with the itemscope attribute can be associated with an item using the global attribute itemref
84    pub item_ref: std::option::Option<std::borrow::Cow<'static, str>>,
85    /// itemscope is a boolean global attribute that defines the scope of associated metadata
86    pub item_scope: std::option::Option<std::borrow::Cow<'static, str>>,
87    /// The global attribute itemtype specifies the URL of the vocabulary that will be used to define itemprop's (item properties) in the data structure
88    pub item_type: std::option::Option<std::borrow::Cow<'static, str>>,
89    /// The lang global attribute helps define the language of an element: the language that non-editable elements are written in, or the language that the editable elements should be written in by the user
90    pub lang: std::option::Option<std::borrow::Cow<'static, str>>,
91    /// The nonce global attribute is a content attribute defining a cryptographic nonce ("number used once") which can be used by Content Security Policy to determine whether or not a given fetch will be allowed to proceed for a given element
92    pub nonce: std::option::Option<std::borrow::Cow<'static, str>>,
93    /// The part global attribute contains a space-separated list of the part names of the element
94    pub part: std::option::Option<std::borrow::Cow<'static, str>>,
95    /// The slot global attribute assigns a slot in a shadow DOM shadow tree to an element: An element with a slot attribute is assigned to the slot created by the <slot> element whose name attribute's value matches that slot attribute's value
96    pub slot: std::option::Option<std::borrow::Cow<'static, str>>,
97    /// The spellcheck global attribute is an enumerated attribute that defines whether the element may be checked for spelling errors
98    pub spellcheck: std::option::Option<std::borrow::Cow<'static, str>>,
99    /// The style global attribute contains CSS styling declarations to be applied to the element
100    pub style: std::option::Option<std::borrow::Cow<'static, str>>,
101    /// The tabindex global attribute allows developers to make HTML elements focusable, allow or prevent them from being sequentially focusable (usually with the Tab key, hence the name) and determine their relative ordering for sequential focus navigation
102    pub tab_index: std::option::Option<i64>,
103    /// The title global attribute contains text representing advisory information related to the element it belongs to
104    pub title: std::option::Option<std::borrow::Cow<'static, str>>,
105    /// The translate global attribute is an enumerated attribute that is used to specify whether an element's translatable attribute values and its Text node children should be translated when the page is localized, or whether to leave them unchanged
106    pub translate: bool,
107}
108impl std::fmt::Display for GlobalAttributes {
109    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110        if let Some(field) = self.access_key.as_ref() {
111            write!(writer, r#" accesskey="{field}""#)?;
112        }
113        if let Some(field) = self.auto_capitalize.as_ref() {
114            write!(writer, r#" autocapitalize="{field}""#)?;
115        }
116        if self.autofocus {
117            write!(writer, r#" autofocus"#)?;
118        }
119        if let Some(field) = self.class.as_ref() {
120            write!(writer, r#" class="{field}""#)?;
121        }
122        if let Some(field) = self.content_editable.as_ref() {
123            write!(writer, r#" contenteditable="{field}""#)?;
124        }
125        if let Some(field) = self.direction.as_ref() {
126            write!(writer, r#" dir="{field}""#)?;
127        }
128        if self.draggable {
129            write!(writer, r#" draggable"#)?;
130        }
131        if let Some(field) = self.enter_key_hint.as_ref() {
132            write!(writer, r#" enterkeyhint="{field}""#)?;
133        }
134        if let Some(field) = self.export_parts.as_ref() {
135            write!(writer, r#" exportparts="{field}""#)?;
136        }
137        if let Some(field) = self.hidden.as_ref() {
138            write!(writer, r#" hidden="{field}""#)?;
139        }
140        if let Some(field) = self.id.as_ref() {
141            write!(writer, r#" id="{field}""#)?;
142        }
143        if self.inert {
144            write!(writer, r#" inert"#)?;
145        }
146        if let Some(field) = self.input_mode.as_ref() {
147            write!(writer, r#" inputmode="{field}""#)?;
148        }
149        if let Some(field) = self.is_.as_ref() {
150            write!(writer, r#" is="{field}""#)?;
151        }
152        if let Some(field) = self.item_id.as_ref() {
153            write!(writer, r#" itemid="{field}""#)?;
154        }
155        if let Some(field) = self.item_prop.as_ref() {
156            write!(writer, r#" itemprop="{field}""#)?;
157        }
158        if let Some(field) = self.item_ref.as_ref() {
159            write!(writer, r#" itemref="{field}""#)?;
160        }
161        if let Some(field) = self.item_scope.as_ref() {
162            write!(writer, r#" itemscope="{field}""#)?;
163        }
164        if let Some(field) = self.item_type.as_ref() {
165            write!(writer, r#" itemtype="{field}""#)?;
166        }
167        if let Some(field) = self.lang.as_ref() {
168            write!(writer, r#" lang="{field}""#)?;
169        }
170        if let Some(field) = self.nonce.as_ref() {
171            write!(writer, r#" nonce="{field}""#)?;
172        }
173        if let Some(field) = self.part.as_ref() {
174            write!(writer, r#" part="{field}""#)?;
175        }
176        if let Some(field) = self.slot.as_ref() {
177            write!(writer, r#" slot="{field}""#)?;
178        }
179        if let Some(field) = self.spellcheck.as_ref() {
180            write!(writer, r#" spellcheck="{field}""#)?;
181        }
182        if let Some(field) = self.style.as_ref() {
183            write!(writer, r#" style="{field}""#)?;
184        }
185        if let Some(field) = self.tab_index.as_ref() {
186            write!(writer, r#" tabindex="{field}""#)?;
187        }
188        if let Some(field) = self.title.as_ref() {
189            write!(writer, r#" title="{field}""#)?;
190        }
191        if self.translate {
192            write!(writer, r#" translate"#)?;
193        }
194        Ok(())
195    }
196}