html_sys/text/
code.rs

1/// The HTML `<code>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code)
4#[doc(alias = "code")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Code {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Describes the role(s) the current element plays in the context of the document.
11    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
13    pub aria_active_descendant_element: std::option::Option<
14        std::borrow::Cow<'static, str>,
15    >,
16    /// Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
17    pub aria_atomic: bool,
18    /// Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for a combobox, searchbox, or textbox and specifies how predictions would be presented if they were made.
19    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. See related aria-roledescription.
21    pub aria_braille_role_description: std::option::Option<
22        std::borrow::Cow<'static, str>,
23    >,
24    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
25    pub aria_busy: bool,
26    /// Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. See related aria-pressed and aria-selected.
27    pub aria_checked: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Defines the total number of columns in a table, grid, or treegrid. See related aria-colindex.
29    pub aria_col_count: std::option::Option<i64>,
30    /// Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. See related aria-colindextext, aria-colcount, and aria-colspan.
31    pub aria_col_index: std::option::Option<i64>,
32    /// Defines a human readable text alternative of aria-colindex. See related aria-rowindextext.
33    pub aria_col_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-colindex and aria-rowspan.
35    pub aria_col_span: std::option::Option<i64>,
36    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
37    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
38    /// Indicates the element that represents the current item within a container or set of related elements.
39    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
40    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
41    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
42    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
43    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
44    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
45    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
47    pub aria_disabled: bool,
48    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
49    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
50    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
51    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
52    /// Indicates whether a grouping element owned or controlled by this element is expanded or collapsed.
53    pub aria_expanded: bool,
54    /// Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
55    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
56    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
57    pub aria_grabbed: bool,
58    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
59    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
60    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
61    pub aria_hidden: bool,
62    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
63    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
64    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
65    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
66    /// Defines the hierarchical level of an element within a structure.
67    pub aria_level: std::option::Option<i64>,
68    /// Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
69    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Indicates whether an element is modal when displayed.
71    pub aria_modal: bool,
72    /// Indicates whether a text box accepts multiple lines of input or only a single line.
73    pub aria_multi_line: bool,
74    /// Indicates that the user can select more than one item from the current selectable descendants.
75    pub aria_multi_selectable: bool,
76    /// Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
77    pub aria_orientation: std::option::Option<std::borrow::Cow<'static, str>>,
78    /// Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. See related aria-controls.
79    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
80    /// Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
81    pub aria_placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
82    /// Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-setsize.
83    pub aria_pos_in_set: std::option::Option<i64>,
84    /// Indicates the current "pressed" state of toggle buttons. See related aria-checked and aria-selected.
85    pub aria_pressed: std::option::Option<std::borrow::Cow<'static, str>>,
86    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
87    pub aria_read_only: bool,
88    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
89    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
90    /// Indicates that user input is required on the element before a form can be submitted.
91    pub aria_required: bool,
92    /// Defines a human-readable, author-localized description for the role of an element.
93    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
94    /// Defines the total number of rows in a table, grid, or treegrid. See related aria-rowindex.
95    pub aria_row_count: std::option::Option<i64>,
96    /// Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. See related aria-rowindextext, aria-rowcount, and aria-rowspan.
97    pub aria_row_index: std::option::Option<i64>,
98    /// Defines a human readable text alternative of aria-rowindex. See related aria-colindextext.
99    pub aria_row_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
100    /// Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-rowindex and aria-colspan.
101    pub aria_row_span: std::option::Option<i64>,
102    /// Indicates the current "selected" state of various widgets. See related aria-checked and aria-pressed.
103    pub aria_selected: bool,
104    /// Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-posinset.
105    pub aria_set_size: std::option::Option<i64>,
106    /// Indicates if items in a table or grid are sorted in ascending or descending order.
107    pub aria_sort: std::option::Option<std::borrow::Cow<'static, str>>,
108    /// Defines the maximum allowed value for a range widget.
109    pub aria_value_max: std::option::Option<f64>,
110    /// Defines the minimum allowed value for a range widget.
111    pub aria_value_min: std::option::Option<f64>,
112    /// Defines the current value for a range widget. See related aria-valuetext.
113    pub aria_value_now: std::option::Option<f64>,
114    /// Defines the human readable text alternative of aria-valuenow for a range widget.
115    pub aria_value_text: std::option::Option<std::borrow::Cow<'static, str>>,
116}
117impl crate::RenderElement for Code {
118    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
119        write!(writer, "<code")?;
120        if let Some(field) = self.role.as_ref() {
121            write!(writer, r#" role="{field}""#)?;
122        }
123        if let Some(field) = self.aria_active_descendant_element.as_ref() {
124            write!(writer, r#" aria-activedescendant="{field}""#)?;
125        }
126        if self.aria_atomic {
127            write!(writer, r#" aria-atomic"#)?;
128        }
129        if let Some(field) = self.aria_auto_complete.as_ref() {
130            write!(writer, r#" aria-autocomplete="{field}""#)?;
131        }
132        if let Some(field) = self.aria_braille_role_description.as_ref() {
133            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
134        }
135        if self.aria_busy {
136            write!(writer, r#" aria-busy"#)?;
137        }
138        if let Some(field) = self.aria_checked.as_ref() {
139            write!(writer, r#" aria-checked="{field}""#)?;
140        }
141        if let Some(field) = self.aria_col_count.as_ref() {
142            write!(writer, r#" aria-colcount="{field}""#)?;
143        }
144        if let Some(field) = self.aria_col_index.as_ref() {
145            write!(writer, r#" aria-colindex="{field}""#)?;
146        }
147        if let Some(field) = self.aria_col_index_text.as_ref() {
148            write!(writer, r#" aria-colindextext="{field}""#)?;
149        }
150        if let Some(field) = self.aria_col_span.as_ref() {
151            write!(writer, r#" aria-colspan="{field}""#)?;
152        }
153        if let Some(field) = self.aria_controls_elements.as_ref() {
154            write!(writer, r#" aria-controls="{field}""#)?;
155        }
156        if let Some(field) = self.aria_current.as_ref() {
157            write!(writer, r#" aria-current="{field}""#)?;
158        }
159        if let Some(field) = self.aria_described_by_elements.as_ref() {
160            write!(writer, r#" aria-describedby="{field}""#)?;
161        }
162        if let Some(field) = self.aria_description.as_ref() {
163            write!(writer, r#" aria-description="{field}""#)?;
164        }
165        if let Some(field) = self.aria_details_elements.as_ref() {
166            write!(writer, r#" aria-details="{field}""#)?;
167        }
168        if self.aria_disabled {
169            write!(writer, r#" aria-disabled"#)?;
170        }
171        if let Some(field) = self.aria_drop_effect.as_ref() {
172            write!(writer, r#" aria-dropeffect="{field}""#)?;
173        }
174        if let Some(field) = self.aria_error_message_elements.as_ref() {
175            write!(writer, r#" aria-errormessage="{field}""#)?;
176        }
177        if self.aria_expanded {
178            write!(writer, r#" aria-expanded"#)?;
179        }
180        if let Some(field) = self.aria_flow_to_elements.as_ref() {
181            write!(writer, r#" aria-flowto="{field}""#)?;
182        }
183        if self.aria_grabbed {
184            write!(writer, r#" aria-grabbed"#)?;
185        }
186        if let Some(field) = self.aria_has_popup.as_ref() {
187            write!(writer, r#" aria-haspopup="{field}""#)?;
188        }
189        if self.aria_hidden {
190            write!(writer, r#" aria-hidden"#)?;
191        }
192        if let Some(field) = self.aria_invalid.as_ref() {
193            write!(writer, r#" aria-invalid="{field}""#)?;
194        }
195        if let Some(field) = self.aria_key_shortcuts.as_ref() {
196            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
197        }
198        if let Some(field) = self.aria_level.as_ref() {
199            write!(writer, r#" aria-level="{field}""#)?;
200        }
201        if let Some(field) = self.aria_live.as_ref() {
202            write!(writer, r#" aria-live="{field}""#)?;
203        }
204        if self.aria_modal {
205            write!(writer, r#" aria-modal"#)?;
206        }
207        if self.aria_multi_line {
208            write!(writer, r#" aria-multiline"#)?;
209        }
210        if self.aria_multi_selectable {
211            write!(writer, r#" aria-multiselectable"#)?;
212        }
213        if let Some(field) = self.aria_orientation.as_ref() {
214            write!(writer, r#" aria-orientation="{field}""#)?;
215        }
216        if let Some(field) = self.aria_owns_elements.as_ref() {
217            write!(writer, r#" aria-owns="{field}""#)?;
218        }
219        if let Some(field) = self.aria_placeholder.as_ref() {
220            write!(writer, r#" aria-placeholder="{field}""#)?;
221        }
222        if let Some(field) = self.aria_pos_in_set.as_ref() {
223            write!(writer, r#" aria-posinset="{field}""#)?;
224        }
225        if let Some(field) = self.aria_pressed.as_ref() {
226            write!(writer, r#" aria-pressed="{field}""#)?;
227        }
228        if self.aria_read_only {
229            write!(writer, r#" aria-readonly"#)?;
230        }
231        if let Some(field) = self.aria_relevant.as_ref() {
232            write!(writer, r#" aria-relevant="{field}""#)?;
233        }
234        if self.aria_required {
235            write!(writer, r#" aria-required"#)?;
236        }
237        if let Some(field) = self.aria_role_description.as_ref() {
238            write!(writer, r#" aria-roledescription="{field}""#)?;
239        }
240        if let Some(field) = self.aria_row_count.as_ref() {
241            write!(writer, r#" aria-rowcount="{field}""#)?;
242        }
243        if let Some(field) = self.aria_row_index.as_ref() {
244            write!(writer, r#" aria-rowindex="{field}""#)?;
245        }
246        if let Some(field) = self.aria_row_index_text.as_ref() {
247            write!(writer, r#" aria-rowindextext="{field}""#)?;
248        }
249        if let Some(field) = self.aria_row_span.as_ref() {
250            write!(writer, r#" aria-rowspan="{field}""#)?;
251        }
252        if self.aria_selected {
253            write!(writer, r#" aria-selected"#)?;
254        }
255        if let Some(field) = self.aria_set_size.as_ref() {
256            write!(writer, r#" aria-setsize="{field}""#)?;
257        }
258        if let Some(field) = self.aria_sort.as_ref() {
259            write!(writer, r#" aria-sort="{field}""#)?;
260        }
261        if let Some(field) = self.aria_value_max.as_ref() {
262            write!(writer, r#" aria-valuemax="{field}""#)?;
263        }
264        if let Some(field) = self.aria_value_min.as_ref() {
265            write!(writer, r#" aria-valuemin="{field}""#)?;
266        }
267        if let Some(field) = self.aria_value_now.as_ref() {
268            write!(writer, r#" aria-valuenow="{field}""#)?;
269        }
270        if let Some(field) = self.aria_value_text.as_ref() {
271            write!(writer, r#" aria-valuetext="{field}""#)?;
272        }
273        write!(writer, "{}", self.global_attrs)?;
274        write!(writer, "{}", self.data_map)?;
275        write!(writer, ">")?;
276        Ok(())
277    }
278    #[allow(unused_variables)]
279    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
280        write!(writer, "</code>")?;
281        Ok(())
282    }
283}
284impl std::fmt::Display for Code {
285    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
286        use crate::RenderElement;
287        self.write_opening_tag(writer)?;
288        self.write_closing_tag(writer)?;
289        Ok(())
290    }
291}
292impl std::ops::Deref for Code {
293    type Target = crate::GlobalAttributes;
294    fn deref(&self) -> &Self::Target {
295        &self.global_attrs
296    }
297}
298impl std::ops::DerefMut for Code {
299    fn deref_mut(&mut self) -> &mut Self::Target {
300        &mut self.global_attrs
301    }
302}