From e8ba4e63c2c9bec68a74716168c99e485512fbe5 Mon Sep 17 00:00:00 2001 From: dangiu Date: Thu, 20 Aug 2026 17:13:55 +0200 Subject: [PATCH] fix: dictionary definition containing html in body are now rendered correclty --- crates/core/src/view/dictionary/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/core/src/view/dictionary/mod.rs b/crates/core/src/view/dictionary/mod.rs index 26311247..fc1a2807 100644 --- a/crates/core/src/view/dictionary/mod.rs +++ b/crates/core/src/view/dictionary/mod.rs @@ -1,5 +1,6 @@ mod bottom_bar; +use lazy_static::lazy_static; use regex::Regex; use crate::device::CURRENT_DEVICE; use crate::framebuffer::{Framebuffer, UpdateMode, Pixmap}; @@ -29,6 +30,13 @@ use self::bottom_bar::BottomBar; const VIEWER_STYLESHEET: &str = "css/dictionary.css"; const USER_STYLESHEET: &str = "css/dictionary-user.css"; +lazy_static! { + // Many dict-format entries mix plain text with inline markup (e.g. `
` between senses, + // `` cross-references) instead of being pure HTML from the very first + // character, so `starts_with('<')` alone misses them. + static ref HTML_TAG: Regex = Regex::new(r"]*)?/?>").unwrap(); +} + pub struct Dictionary { id: Id, rect: Rectangle, @@ -67,7 +75,7 @@ fn query_to_content(query: &str, language: &String, fuzzy: bool, target: Option< if !body.trim_start().starts_with("{}\n", head.replace('<', "<").replace('>', ">"))); } - if body.trim_start().starts_with('<') { + if HTML_TAG.is_match(&body) { content.push_str(&body); } else { content.push_str(&format!("
{}
", body.replace('<', "<").replace('>', ">")));