From 94c85a3c0794224001dfc14c523bd9eacfb05516 Mon Sep 17 00:00:00 2001 From: zhangzheng <826193720@qq.com> Date: Tue, 14 Jul 2026 20:33:25 +0800 Subject: [PATCH] [fix] adapt readability js --- src/crates/execution/tool-execution/Cargo.toml | 3 ++- .../execution/tool-execution/src/web_readable.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/crates/execution/tool-execution/Cargo.toml b/src/crates/execution/tool-execution/Cargo.toml index 4b9c72e5af..5a057670fe 100644 --- a/src/crates/execution/tool-execution/Cargo.toml +++ b/src/crates/execution/tool-execution/Cargo.toml @@ -20,10 +20,11 @@ htmd = { version = "0.5.4", optional = true } ignore = { workspace = true } legible = { version = "0.4.2", optional = true } log = { workspace = true } -readability-js = { version = "0.1.5", optional = true } regex = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } vte = { workspace = true, features = ["ansi"] } +[target.'cfg(not(target_env = ohos))'.dependencies] +readability-js = { version = "0.1.5", optional = true } diff --git a/src/crates/execution/tool-execution/src/web_readable.rs b/src/crates/execution/tool-execution/src/web_readable.rs index 75c3e142c9..b1d5546c3c 100644 --- a/src/crates/execution/tool-execution/src/web_readable.rs +++ b/src/crates/execution/tool-execution/src/web_readable.rs @@ -1,5 +1,6 @@ use htmd::HtmlToMarkdown; use legible::{parse as parse_legible, Error as LegibleError, Options as LegibleOptions}; +#[cfg(not(target_env = "ohos"))] use readability_js::{Readability, ReadabilityOptions}; use regex::{Captures, Regex}; @@ -73,10 +74,15 @@ pub fn extract_markdown_with_text_fallback( // Keep the existing extractor order. Local extraction experiments across // article, documentation, wiki, and forum pages showed `legible` gives the // best current quality/latency balance, with readability-js as fallback. - for extractor in [ + #[cfg(not(target_env = "ohos"))] + let extractors: [ExtractorFn; 2] = [ attempt_legible as ExtractorFn, attempt_readability_js as ExtractorFn, - ] { + ]; + #[cfg(target_env = "ohos")] + let extractors: [ExtractorFn; 1] = [attempt_legible as ExtractorFn]; + + for extractor in extractors { let Ok(candidate) = extractor(html, base_url) else { continue; }; @@ -145,6 +151,7 @@ fn attempt_legible(html: &str, base_url: &str) -> Result Result { let reader = Readability::new() .map_err(|err| format!("Failed to initialize readability-js: {}", err))?;