pub mod markdown;
pub mod structured;
pub mod text;
use scraper::Html;
use crate::compress::compress_block;
use crate::types::{ContentType, UrlReference};
pub(crate) fn is_skippable(name: &str) -> bool {
matches!(
name,
"script" | "style" | "noscript" | "svg" | "head" | "template" | "iframe"
)
}
pub struct Converted {
pub content: String,
pub references: Vec<UrlReference>,
}
pub fn convert_parsed(doc: &Html, base_url: &str, content_type: ContentType) -> Converted {
match content_type {
ContentType::Text => {
let (body, references) = text::text_with_refs(doc, base_url);
Converted {
content: compress_block(&body),
references,
}
}
ContentType::Markdown => {
let (md, references) = markdown::markdown_with_refs(doc, base_url);
Converted {
content: compress_block(&md),
references,
}
}
ContentType::Structured => {
let parsed = structured::structured(doc, base_url);
Converted {
content: structured::to_json(&parsed),
references: parsed.references,
}
}
}
}
pub fn convert(html: &str, base_url: &str, content_type: ContentType) -> Converted {
convert_parsed(&Html::parse_document(html), base_url, content_type)
}