Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ homepage = "https://murroughfoley.com"
repository = "https://github.com/Murrough-Foley/rs-trafilatura"
documentation = "https://docs.rs/rs-trafilatura"
readme = "README.md"
keywords = ["html", "content-extraction", "web-scraping", "trafilatura", "boilerplate-removal"]
keywords = [
"html",
"content-extraction",
"web-scraping",
"trafilatura",
"boilerplate-removal",
]
categories = ["parser-implementations", "web-programming", "text-processing"]

[dependencies]
tracing = "0.1"
html-cleaning = "0.3"
quick_html2md = "0.2"
web-page-classifier = "0.1"
dom_query = "0.24" # Primary DOM manipulation
tendril = "0.4" # Zero-copy text operations via StrTendril
dom_query = "0.24" # Primary DOM manipulation
tendril = "0.4" # Zero-copy text operations via StrTendril
thiserror = "2.0"
regex = "1.11"
regex = "1.12"
chrono = "0.4"
encoding_rs = "0.8"
serde = { version = "1.0", features = ["derive"] }
Expand Down Expand Up @@ -57,12 +64,12 @@ pedantic = { level = "warn", priority = -1 }
unwrap_used = "deny"
expect_used = "deny"
# Allow these pedantic lints - they're too strict or low-value for this codebase
needless_raw_string_hashes = "allow" # Stylistic preference
similar_names = "allow" # matched/matches, text_len/text_length are clear
cast_precision_loss = "allow" # Intentional in scoring calculations
items_after_statements = "allow" # Valid Rust style for inline helpers
doc_markdown = "allow" # Too strict about backticks
float_cmp = "allow" # Approximate comparisons are intentional
too_many_lines = "allow" # Some complex functions need to be long
missing_errors_doc = "allow" # Error types are self-explanatory
missing_panics_doc = "allow" # We don't panic in production code
needless_raw_string_hashes = "allow" # Stylistic preference
similar_names = "allow" # matched/matches, text_len/text_length are clear
cast_precision_loss = "allow" # Intentional in scoring calculations
items_after_statements = "allow" # Valid Rust style for inline helpers
doc_markdown = "allow" # Too strict about backticks
float_cmp = "allow" # Approximate comparisons are intentional
too_many_lines = "allow" # Some complex functions need to be long
missing_errors_doc = "allow" # Error types are self-explanatory
missing_panics_doc = "allow" # We don't panic in production code
19 changes: 10 additions & 9 deletions src/bin/batch_markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use std::path::PathBuf;
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 3 {
eprintln!("Usage: batch_markdown <input_dir> <output_dir>");
tracing::error!("Usage: batch_markdown <input_dir> <output_dir>");
std::process::exit(1);
}

let input_dir = PathBuf::from(&args[1]);
let output_dir = PathBuf::from(&args[2]);

if !input_dir.is_dir() {
eprintln!("Input directory does not exist: {}", input_dir.display());
tracing::error!("Input directory does not exist: {}", input_dir.display());
std::process::exit(1);
}

Expand Down Expand Up @@ -59,7 +59,7 @@ fn main() {
let html = match fs::read_to_string(&path) {
Ok(h) => h,
Err(e) => {
eprintln!("[{}/{}] ERROR reading {}: {}", i + 1, total, stem, e);
tracing::error!("[{}/{}] ERROR reading {}: {}", i + 1, total, stem, e);
failed += 1;
continue;
}
Expand All @@ -68,12 +68,10 @@ fn main() {
match extract_with_options(&html, &options) {
Ok(result) => {
// Prefer markdown, fall back to plain text
let content = result
.content_markdown
.unwrap_or(result.content_text);
let content = result.content_markdown.unwrap_or(result.content_text);

if content.trim().is_empty() {
eprintln!(
tracing::warn!(
"[{}/{}] EMPTY: {} (confidence: {:.2})",
i + 1,
total,
Expand All @@ -96,7 +94,10 @@ fn main() {
if let Some(ref date) = result.metadata.date {
md.push_str(&format!("date: \"{}\"\n", date.to_rfc3339()));
}
md.push_str(&format!("source_file: \"{}\"\n", path.file_name().unwrap().to_string_lossy()));
md.push_str(&format!(
"source_file: \"{}\"\n",
path.file_name().unwrap().to_string_lossy()
));
md.push_str(&format!("confidence: {:.2}\n", result.extraction_quality));
if let Some(ref pt) = result.metadata.page_type {
md.push_str(&format!("page_type: \"{}\"\n", pt));
Expand All @@ -116,7 +117,7 @@ fn main() {
success += 1;
}
Err(e) => {
eprintln!("[{}/{}] EXTRACT ERROR {}: {}", i + 1, total, stem, e);
tracing::error!("[{}/{}] EXTRACT ERROR {}: {}", i + 1, total, stem, e);
failed += 1;
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/bin/extract_stdin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Simple CLI that reads HTML from stdin and outputs JSON to stdout.
//! Used by the text-extraction-benchmark Python wrapper.

use rs_trafilatura::{extract_with_options, Options};
use rs_trafilatura::page_type::PageType;
use rs_trafilatura::{extract_with_options, Options};
use serde::Serialize;
use std::io::{self, Read};

Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() {
url = Some(args[i + 1].clone());
i += 2;
} else {
eprintln!("--url requires a value");
tracing::error!("--url requires a value");
std::process::exit(1);
}
}
Expand All @@ -51,13 +51,13 @@ fn main() {
match args[i + 1].parse::<PageType>() {
Ok(pt) => page_type_override = Some(pt),
Err(e) => {
eprintln!("Invalid --page-type: {e}");
tracing::error!("Invalid --page-type: {e}");
std::process::exit(1);
}
}
i += 2;
} else {
eprintln!("--page-type requires a value");
tracing::error!("--page-type requires a value");
std::process::exit(1);
}
}
Expand All @@ -69,14 +69,16 @@ fn main() {
markdown = true;
i += 1;
}
_ => { i += 1; }
_ => {
i += 1;
}
}
}

// Read HTML from stdin
let mut html = String::new();
if io::stdin().read_to_string(&mut html).is_err() {
eprintln!("Failed to read from stdin");
tracing::error!("Failed to read from stdin");
std::process::exit(1);
}

Expand All @@ -85,9 +87,21 @@ fn main() {
url,
page_type: page_type_override,
output_markdown: markdown,
include_tables: if markdown { true } else { Options::default().include_tables },
include_links: if markdown { true } else { Options::default().include_links },
include_formatting: if markdown { true } else { Options::default().include_formatting },
include_tables: if markdown {
true
} else {
Options::default().include_tables
},
include_links: if markdown {
true
} else {
Options::default().include_links
},
include_formatting: if markdown {
true
} else {
Options::default().include_formatting
},
..Options::default()
};

Expand Down
Loading