html5ever/tree_builder/
types.rs

1// Copyright 2014-2017 The html5ever Project Developers. See the
2// COPYRIGHT file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! Types used within the tree builder code. Not exported to users.
11
12use crate::tokenizer::states::RawKind;
13use crate::tokenizer::Tag;
14
15use crate::tendril::StrTendril;
16
17#[derive(PartialEq, Eq, Copy, Clone, Debug)]
18pub(crate) enum InsertionMode {
19    /// <https://html.spec.whatwg.org/#the-initial-insertion-mode>
20    Initial,
21    /// <https://html.spec.whatwg.org/#the-before-html-insertion-mode>
22    BeforeHtml,
23    /// <https://html.spec.whatwg.org/#the-before-head-insertion-mode>
24    BeforeHead,
25    /// <https://html.spec.whatwg.org/#parsing-main-inhead>
26    InHead,
27    /// <https://html.spec.whatwg.org/#parsing-main-inheadnoscript>
28    InHeadNoscript,
29    /// <https://html.spec.whatwg.org/#the-after-head-insertion-mode>
30    AfterHead,
31    /// <https://html.spec.whatwg.org/#parsing-main-inbody>
32    InBody,
33    /// <https://html.spec.whatwg.org/#parsing-main-incdata>
34    Text,
35    /// <https://html.spec.whatwg.org/#parsing-main-intable>
36    InTable,
37    /// <https://html.spec.whatwg.org/#parsing-main-intabletext>
38    InTableText,
39    /// <https://html.spec.whatwg.org/#parsing-main-incaption>
40    InCaption,
41    /// <https://html.spec.whatwg.org/#parsing-main-incolgroup>
42    InColumnGroup,
43    /// <https://html.spec.whatwg.org/#parsing-main-intbody>
44    InTableBody,
45    /// <https://html.spec.whatwg.org/#parsing-main-intr>
46    InRow,
47    /// <https://html.spec.whatwg.org/#parsing-main-intd>
48    InCell,
49    /// <https://html.spec.whatwg.org/#parsing-main-intemplate>
50    InTemplate,
51    /// <https://html.spec.whatwg.org/#parsing-main-afterbody>
52    AfterBody,
53    /// <https://html.spec.whatwg.org/#parsing-main-inframeset>
54    InFrameset,
55    /// <https://html.spec.whatwg.org/#parsing-main-afterframeset>
56    AfterFrameset,
57    /// <https://html.spec.whatwg.org/#the-after-after-body-insertion-mode>
58    AfterAfterBody,
59    /// <https://html.spec.whatwg.org/#the-after-after-frameset-insertion-mode>
60    AfterAfterFrameset,
61}
62
63#[derive(PartialEq, Eq, Copy, Clone, Debug)]
64pub(crate) enum SplitStatus {
65    NotSplit,
66    Whitespace,
67    NotWhitespace,
68}
69
70/// A subset/refinement of `tokenizer::Token`.  Everything else is handled
71/// specially at the beginning of `process_token`.
72#[derive(PartialEq, Eq, Clone, Debug)]
73#[allow(clippy::enum_variant_names)]
74pub(crate) enum Token {
75    Tag(Tag),
76    Comment(StrTendril),
77    Characters(SplitStatus, StrTendril),
78    NullCharacter,
79    Eof,
80}
81
82pub(crate) enum ProcessResult<Handle> {
83    Done,
84    DoneAckSelfClosing,
85    SplitWhitespace(StrTendril),
86    Reprocess(InsertionMode, Token),
87    #[allow(dead_code)] // FIXME
88    ReprocessForeign(Token),
89    Script(Handle),
90    ToPlaintext,
91    ToRawData(RawKind),
92    EncodingIndicator(StrTendril),
93}
94
95pub(crate) enum FormatEntry<Handle> {
96    Element(Handle, Tag),
97    Marker,
98}
99
100pub(crate) enum InsertionPoint<Handle> {
101    /// Insert as last child in this parent.
102    LastChild(Handle),
103    #[allow(dead_code)] // FIXME
104    /// Insert before this following sibling.
105    BeforeSibling(Handle),
106    /// Insertion point is decided based on existence of element's parent node.
107    TableFosterParenting {
108        element: Handle,
109        prev_element: Handle,
110    },
111}