refactor: extract block label helper
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
//! 或 editor command。类型字段使用 `pub(crate)` 以支持跨模块访问,保持结构
|
||||
//! 和语义同构。
|
||||
|
||||
use web_sys::Element;
|
||||
|
||||
/// Hovered block 的共享状态:索引、类型标签、位置和高度。
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct HoveredBlockState {
|
||||
@@ -45,3 +47,22 @@ pub(crate) struct PendingDragState {
|
||||
pub(crate) start_x: i32,
|
||||
pub(crate) start_y: i32,
|
||||
}
|
||||
|
||||
pub(crate) fn block_label_for_element(block: &Element) -> String {
|
||||
match block.get_attribute("data-type").as_deref() {
|
||||
Some("taskList") => "Todo 列表".to_string(),
|
||||
Some("taskItem") => "Todo 项".to_string(),
|
||||
_ => match block.tag_name().as_str() {
|
||||
"H1" => "一级标题".to_string(),
|
||||
"H2" => "二级标题".to_string(),
|
||||
"H3" => "三级标题".to_string(),
|
||||
"P" => "段落".to_string(),
|
||||
"UL" => "无序列表".to_string(),
|
||||
"OL" => "有序列表".to_string(),
|
||||
"BLOCKQUOTE" => "引用块".to_string(),
|
||||
"PRE" => "代码块".to_string(),
|
||||
"HR" => "分割线".to_string(),
|
||||
other => format!("块节点 {other}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user