use crate::facts::{Facts, Import, Span};
use crate::style::selector_use;
use crate::syntax::Language;
use crate::token::{Mode, Token, TokenKind, Tokenizer};
#[must_use]
pub fn extract(source: &str, language: Language) -> Facts {
let tokens = Tokenizer::new(source, language)
.mode(Mode::Lite)
.collect::<Vec<_>>();
let mut state = Extractor {
source,
tokens: &tokens,
language,
facts: Facts::default(),
tag: String::new(),
text_start: None,
};
state.run();
state.facts
}
fn names_a_file_in_text(tag: &str) -> bool {
matches!(tag, "module" | "include" | "xi:include" | "systemid")
}
fn names_a_file(language: Language, tag: &str, attribute: &str) -> bool {
if language == Language::Xml {
return matches!(
attribute,
"include" | "href" | "src" | "schemalocation" | "location" | "file" | "path"
);
}
match attribute {
"href" => matches!(tag, "link" | "use"),
"src" => matches!(
tag,
"script" | "img" | "iframe" | "audio" | "video" | "source" | "embed" | "track"
),
"srcset" | "data-src" => true,
_ => false,
}
}
struct Extractor<'source, 'tokens> {
source: &'source str,
tokens: &'tokens [Token],
language: Language,
facts: Facts,
tag: String,
text_start: Option<(usize, String)>,
}
mod extractor;
#[cfg(test)]
mod tests;