Skip to main content

blitz_dom/
html.rs

1use crate::{BaseDocument, Document, DocumentConfig, DocumentMutator, PlainDocument};
2use blitz_traits::node_id::NodeId;
3
4pub trait HtmlParserProvider {
5    fn parse_inner_html<'m, 'doc>(
6        &self,
7        mutr: &'m mut DocumentMutator<'doc>,
8        element_id: NodeId,
9        html: &str,
10    );
11
12    /// Parse a full HTML document (e.g. the contents of an `<iframe>`).
13    ///
14    /// The default implementation ignores the HTML and returns an empty document.
15    fn parse_document(&self, html: &str, config: DocumentConfig) -> Box<dyn Document> {
16        let _ = html;
17        Box::new(PlainDocument(BaseDocument::new(config)))
18    }
19}
20
21pub struct DummyHtmlParserProvider;
22impl HtmlParserProvider for DummyHtmlParserProvider {
23    fn parse_inner_html<'m, 'doc>(
24        &self,
25        mutr: &'m mut DocumentMutator<'doc>,
26        element_id: NodeId,
27        html: &str,
28    ) {
29        let _ = mutr;
30        let _ = element_id;
31        let _ = html;
32        // Do nothing for now
33        //
34        // TODO: do something:
35        // - Print warning?
36        // - Parse HTML as plain text?
37    }
38}