// Copyright 2014-2017 The html5ever Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 or the MIT license
// , at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The tree builder rules, as a single, enormous nested match expression.
use markup5ever::{expanded_name, local_name, namespace_prefix, namespace_url, ns};
use crate::tokenizer::states::{Plaintext, Rawtext, Rcdata, ScriptData};
use crate::tree_builder::tag_sets::*;
use crate::tree_builder::types::*;
use std::borrow::ToOwned;
use crate::tendril::SliceExt;
fn any_not_whitespace(x: &StrTendril) -> bool {
// FIXME: this might be much faster as a byte scan
x.chars().any(|c| !is_ascii_whitespace(c))
}
fn current_node(open_elems: &[Handle]) -> &Handle {
open_elems.last().expect("no current element")
}
#[doc(hidden)]
impl TreeBuilder
where
Handle: Clone,
Sink: TreeSink,
{
fn step(&mut self, mode: InsertionMode, token: Token) -> ProcessResult {
self.debug_step(mode, &token);
match mode {
//§ the-initial-insertion-mode
Initial => match_token!(token {
CharacterTokens(NotSplit, text) => SplitWhitespace(text),
CharacterTokens(Whitespace, _) => Done,
CommentToken(text) => self.append_comment_to_doc(text),
token => {
if !self.opts.iframe_srcdoc {
self.unexpected(&token);
self.set_quirks_mode(Quirks);
}
Reprocess(BeforeHtml, token)
}
}),
//§ the-before-html-insertion-mode
BeforeHtml => match_token!(token {
CharacterTokens(NotSplit, text) => SplitWhitespace(text),
CharacterTokens(Whitespace, _) => Done,
CommentToken(text) => self.append_comment_to_doc(text),
tag @ => {
self.create_root(tag.attrs);
self.mode = BeforeHead;
Done
}