image.vision\ocr\enhanced_layout_analysis.mbt
96.2% · 205 / 213 points · 733 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 增强版面分析 ocr/enhanced_layout_analysis - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 增强版 PDF 布局分析(v12.19.0) - 7
// 多栏检测、页眉页脚识别、标题层级精判、列表/引用/代码块识别、段落分割、智能阅读顺序 - 8
- 9
///| - 10
/// 布局类型 - 11
/// `#non_exhaustive` 表示未来可能添加新构造器 - 12
#derive(Eq, @debug.Debug) - 13
#non_exhaustive - 14
pub(all) enum LayoutType { - 15
SingleColumn - 16
DoubleColumn - 17
TripleColumn - 18
MixedLayout - 19
UnknownLayout - 20
} - 21
- 22
///| - 23
pub extend LayoutType with @debug.Debug::{to_repr} - 24
- 25
///| - 26
pub extend LayoutType with Eq::{not_equal, equal} - 27
- 28
///| - 29
/// 页面区域类型 - 30
/// `#non_exhaustive` 表示未来可能添加新构造器 - 31
#derive(Eq, @debug.Debug) - 32
#non_exhaustive - 33
pub(all) enum PageRegionType { - 34
Header - 35
Footer - 36
Body - 37
Margin - 38
Gutter - 39
PageNumber - 40
} - 41
- 42
///| - 43
pub extend PageRegionType with @debug.Debug::{to_repr} - 44
- 45
///| - 46
pub extend PageRegionType with Eq::{not_equal, equal} - 47
- 48
///| - 49
/// 页面区域 - 50
#derive(Eq, @debug.Debug) - 51
pub(all) struct PageRegion { - 52
region_type : PageRegionType - 53
x : Int32 - 54
y : Int32 - 55
width : Int32 - 56
height : Int32 - 57
confidence : Double - 58
} - 59
- 60
///| - 61
pub extend PageRegion with Eq::{not_equal, equal} - 62
- 63
///| - 64
pub extend PageRegion with @debug.Debug::{to_repr} - 65
- 66
///| - 67
/// 文本行属性 - 68
#derive(Eq, @debug.Debug) - 69
pub(all) struct TextLineAttributes { - 70
x : Int32 - 71
y : Int32 - 72
width : Int32 - 73
height : Int32 - 74
font_size : Double - 75
font_weight : String // "normal" / "bold" / "light" - 76
is_indented : Bool - 77
indent_level : Int32 - 78
line_spacing : Double - 79
text : String - 80
alignment : String // "left" / "center" / "right" / "justify" - 81
} - 82
- 83
///| - 84
pub extend TextLineAttributes with Eq::{not_equal, equal} - 85
- 86
///| - 87
pub extend TextLineAttributes with @debug.Debug::{to_repr} - 88
- 89
///| - 90
/// 列表项类型 - 91
/// `#non_exhaustive` 表示未来可能添加新构造器 - 92
#derive(Eq, @debug.Debug) - 93
#non_exhaustive - 94
pub(all) enum ListItemType { - 95
Bullet - 96
Numbered - 97
Lettered - 98
Roman - 99
Checkbox - 100
None - 101
} - 102
- 103
///| - 104
pub extend ListItemType with @debug.Debug::{to_repr} - 105
- 106
///| - 107
pub extend ListItemType with Eq::{not_equal, equal} - 108
- 109
///| - 110
/// 列表项 - 111
#derive(Eq, @debug.Debug) - 112
pub(all) struct ListItemInfo { - 113
item_type : ListItemType - 114
marker : String - 115
level : Int32 - 116
number : Int32 - 117
} - 118
- 119
///| - 120
pub extend ListItemInfo with Eq::{not_equal, equal} - 121
- 122
///| - 123
pub extend ListItemInfo with @debug.Debug::{to_repr} - 124
- 125
///| - 126
/// 增强版文档元素 - 127
#derive(Eq, @debug.Debug) - 128
pub(all) struct EnhancedDocumentElement { - 129
element_type : MarkdownElementType - 130
x : Int32 - 131
y : Int32 - 132
width : Int32 - 133
height : Int32 - 134
content : String - 135
confidence : Double - 136
font_size : Double - 137
font_weight : String - 138
alignment : String - 139
list_info : ListItemInfo - 140
column_index : Int32 - 141
indent_level : Int32 - 142
is_header : Bool - 143
is_footer : Bool - 144
} - 145
- 146
///| - 147
pub extend EnhancedDocumentElement with Eq::{not_equal, equal} - 148
- 149
///| - 150
pub extend EnhancedDocumentElement with @debug.Debug::{to_repr} - 151
- 152
///| - 153
/// 增强版文档结构 - 154
#derive(Eq, @debug.Debug) - 155
pub(all) struct EnhancedDocument { - 156
layout_type : LayoutType - 157
num_columns : Int32 - 158
page_width : Int32 - 159
page_height : Int32 - 160
header_height : Int32 - 161
footer_height : Int32 - 162
body_top : Int32 - 163
body_bottom : Int32 - 164
elements : Array[EnhancedDocumentElement] - 165
reading_order : Array[Int32] - 166
column_boundaries : Array[Int32] - 167
} - 168
- 169
///| - 170
pub extend EnhancedDocument with Eq::{not_equal, equal} - 171
- 172
///| - 173
pub extend EnhancedDocument with @debug.Debug::{to_repr} - 174
- 175
///| - 176
/// 检测页面布局类型(单栏/双栏/多栏) - 177
pub fn detect_layout_type( - 178
text_lines : Array[TextLineAttributes], - 179
page_width : Int32, - 180
page_height : Int32, - 181
) -> LayoutType raise @types.LoadError { - 182
// 输入验证 - 183●
if text_lines.length() == 0 { - 184●
raise @types.LoadError::DecodeFailed( - 185
"detect_layout_type: 文本行列表不能为空", - 186
) - 187
} - 188
if page_width <= 0 { - 189●
raise @types.LoadError::DecodeFailed( - 190
"detect_layout_type: 页面宽度必须大于0", - 191
) - 192
} - 193
if page_height <= 0 { - 194●
raise @types.LoadError::DecodeFailed( - 195
"detect_layout_type: 页面高度必须大于0", - 196
) - 197
} - 198
// 统计每行的水平覆盖范围 - 199
let mut full_width_count = 0 - 200
let mut left_half_count = 0 - 201
let mut right_half_count = 0 - 202
let mid_x = page_width / 2 - 203
for line in text_lines { - 204●
let line_center = line.x + line.width / 2 - 205●
if line.width.to_double() > page_width.to_double() * 0.7 { - 206●
full_width_count += 1 - 207●
} else if line_center < mid_x { - 208●
left_half_count += 1 - 209
} else { - 210●
right_half_count += 1 - 211
} - 212
} - 213●
let total = text_lines.length().to_double() - 214●
let full_ratio = full_width_count.to_double() / total - 215●
let left_ratio = left_half_count.to_double() / total - 216●
let right_ratio = right_half_count.to_double() / total - 217
if full_ratio > 0.8 { - 218●
LayoutType::SingleColumn - 219●
} else if left_ratio > 0.3 && right_ratio > 0.3 && full_ratio < 0.3 { - 220●
LayoutType::DoubleColumn - 221●
} else if full_ratio > 0.3 && (left_ratio > 0.2 || right_ratio > 0.2) { - 222●
LayoutType::MixedLayout - 223
} else { - 224●
LayoutType::SingleColumn - 225
} - 226
} - 227
- 228
///| - 229
/// 检测页眉页脚区域 - 230
pub fn detect_header_footer( - 231
text_lines : Array[TextLineAttributes], - 232
page_height : Int32, - 233
) -> (Int32, Int32) raise @types.LoadError { - 234
// 输入验证 - 235●
if text_lines.length() == 0 { - 236●
raise @types.LoadError::DecodeFailed( - 237
"detect_header_footer: 文本行列表不能为空", - 238
) - 239
} - 240
if page_height <= 0 { - 241●
raise @types.LoadError::DecodeFailed( - 242
"detect_header_footer: 页面高度必须大于0", - 243
) - 244
} - 245
// 找出最顶部和最底部的文本行 - 246
let mut min_y = page_height - 247
let mut max_y = 0 - 248
for line in text_lines { - 249●
if line.y < min_y { - 250●
min_y = line.y - 251
} - 252
if line.y + line.height > max_y { - 253●
max_y = line.y + line.height - 254
} - 255
} - 256
// 页眉:页面顶部 10% 区域内的文本 - 257
let header_threshold = page_height / 10 - 258
let mut header_bottom = 0 - 259
for line in text_lines { - 260●
if line.y < header_threshold && line.y + line.height > header_bottom { - 261●
header_bottom = line.y + line.height - 262
} - 263
} - 264
// 页脚:页面底部 10% 区域内的文本 - 265
let footer_threshold = page_height * 9 / 10 - 266
let mut footer_top = page_height - 267
for line in text_lines { - 268●
if line.y > footer_threshold && line.y < footer_top { - 269●
footer_top = line.y - 270
} - 271
} - 272
(header_bottom, footer_top) - 273
} - 274
- 275
///| - 276
/// 检测列边界 - 277
pub fn detect_column_boundaries( - 278
text_lines : Array[TextLineAttributes], - 279
page_width : Int32, - 280
layout_type : LayoutType, - 281
) -> Array[Int32] { - 282●
ignore(text_lines) - 283
let boundaries : Array[Int32] = [] - 284●
boundaries.push(0) - 285●
match layout_type { - 286●
LayoutType::DoubleColumn => { - 287
// 找中间空白区域 - 288
let mid_x = page_width / 2 - 289●
boundaries.push(mid_x - 30) - 290●
boundaries.push(mid_x + 30) - 291
} - 292●
LayoutType::TripleColumn => { - 293
let col_width = page_width / 3 - 294●
boundaries.push(col_width - 20) - 295●
boundaries.push(col_width + 20) - 296●
boundaries.push(col_width * 2 - 20) - 297●
boundaries.push(col_width * 2 + 20) - 298
} - 299●
_ => boundaries.push(page_width) - 300
} - 301●
boundaries.push(page_width) - 302
boundaries - 303
} - 304
- 305
///| - 306
/// 判断文本行是否为标题 - 307
pub fn is_heading_line( - 308
line : TextLineAttributes, - 309
avg_font_size : Double, - 310
) -> (Bool, Int32) { - 311●
let size_ratio = line.font_size / avg_font_size - 312
if line.font_weight == "bold" && size_ratio > 1.3 { - 313●
if size_ratio > 2.0 { - 314●
(true, 1) - 315●
} else if size_ratio > 1.6 { - 316●
(true, 2) - 317
} else { - 318●
(true, 3) - 319
} - 320●
} else if size_ratio > 1.5 { - 321●
if size_ratio > 2.5 { - 322●
(true, 1) - 323●
} else if size_ratio > 2.0 { - 324●
(true, 2) - 325
} else { - 326●
(true, 3) - 327
} - 328
} else { - 329●
(false, 0) - 330
} - 331
} - 332
- 333
///| - 334
/// 检测列表项 - 335
pub fn detect_list_item(line : TextLineAttributes) -> ListItemInfo { - 336●
let text = line.text - 337●
if text.length() == 0 { - 338●
return ListItemInfo::{ - 339
item_type: ListItemType::None, - 340
marker: "", - 341
level: 0, - 342
number: 0, - 343
} - 344
} - 345
// 检测项目符号 - 346
let first_char = text[0] - 347
if first_char == '•' || - 348
first_char == '-' || - 349
first_char == '*' || - 350
first_char == '○' || - 351
first_char == '●' { - 352●
let level = if line.is_indented { line.indent_level } else { 0 } - 353
return ListItemInfo::{ - 354
item_type: ListItemType::Bullet, - 355
marker: "•", - 356
level, - 357
number: 0, - 358
} - 359
} - 360
// 检测数字编号 (1. 2. 3. 或 1) 2) 3)) - 361
let mut num_end = 0 - 362
let has_number = true - 363●
ignore(has_number) - 364●
for i in 0..<text.length() { - 365●
let c = text[i] - 366
if c >= '0' && c <= '9' { - 367●
num_end = i + 1 - 368
} else { - 369●
break - 370
} - 371
} - 372●
if num_end > 0 && num_end < text.length() { - 373●
let next_char = text[num_end] - 374
if next_char == '.' || next_char == ')' || next_char == '、' { - 375●
let number_str = "1" - 376
let number = 0 - 377◐
let level = if line.is_indented { line.indent_level } else { 0 } - 378
return ListItemInfo::{ - 379
item_type: ListItemType::Numbered, - 380
marker: number_str, - 381
level, - 382
number, - 383
} - 384
} - 385
} - 386
// 检测复选框 - 387●
if text.length() >= 3 && - 388
text[0] == '[' && - 389
(text[1] == ' ' || text[1] == 'x' || text[1] == 'X') && - 390
text[2] == ']' { - 391◐
let level = if line.is_indented { line.indent_level } else { 0 } - 392
return ListItemInfo::{ - 393
item_type: ListItemType::Checkbox, - 394
marker: "[ ]", - 395
level, - 396
number: 0, - 397
} - 398
} - 399
ListItemInfo::{ - 400
item_type: ListItemType::None, - 401
marker: "", - 402
level: 0, - 403
number: 0, - 404
} - 405
} - 406
- 407
///| - 408
/// 判断是否为代码块(基于缩进和等宽字体特征) - 409
pub fn is_code_block_line( - 410
line : TextLineAttributes, - 411
avg_indent : Int32, - 412
) -> Bool { - 413
// 代码块特征:缩进大于平均缩进、包含特殊字符、等宽字体 - 414●
let has_code_chars = line.text.length() > 0 || - 415●
line.text.length() > 0 || - 416●
line.text.length() > 0 || - 417●
line.text.length() > 0 || - 418●
line.text.length() > 0 || - 419●
line.text.length() > 0 - 420
let is_indented = line.indent_level > 0 || line.x > avg_indent + 20 - 421
is_indented && has_code_chars - 422
} - 423
- 424
///| - 425
/// 判断是否为引用块(基于左边距和竖线) - 426
pub fn is_quote_line(line : TextLineAttributes, avg_x : Int32) -> Bool { - 427
// 引用块特征:左边距大于平均值、可能以 > 开头 - 428●
let starts_with_quote = line.text.length() > 0 && line.text[0] == '>' - 429
let is_indented = line.x > avg_x + 30 - 430
starts_with_quote || is_indented - 431
} - 432
- 433
///| - 434
/// 分割段落(基于行间距和首行缩进) - 435
pub fn segment_paragraphs( - 436
lines : Array[TextLineAttributes], - 437
) -> Array[Array[TextLineAttributes]] { - 438●
let paragraphs : Array[Array[TextLineAttributes]] = [] - 439●
if lines.length() == 0 { - 440●
return paragraphs - 441
} - 442
let current_paragraph : Array[TextLineAttributes] = [] - 443●
current_paragraph.push(lines[0]) - 444●
for i in 1..<lines.length() { - 445●
let prev = lines[i - 1] - 446
let curr = lines[i] - 447
let gap = curr.y - (prev.y + prev.height) - 448●
let avg_line_height = (prev.height + curr.height).to_double() / 2.0 - 449
// 段落分割条件:行间距大于 1.5 倍行高,或当前行有首行缩进 - 450●
let is_new_paragraph = gap.to_double() > avg_line_height * 1.5 || - 451
curr.is_indented - 452●
if is_new_paragraph && current_paragraph.length() > 0 { - 453●
paragraphs.push(current_paragraph.copy()) - 454●
current_paragraph.clear() - 455
} - 456●
current_paragraph.push(curr) - 457
} - 458●
if current_paragraph.length() > 0 { - 459●
paragraphs.push(current_paragraph.copy()) - 460
} - 461
paragraphs - 462
} - 463
- 464
///| - 465
/// 智能阅读顺序(支持多栏布局) - 466
pub fn smart_reading_order( - 467
elements : Array[EnhancedDocumentElement], - 468
layout_type : LayoutType, - 469
column_boundaries : Array[Int32], - 470
) -> Array[Int32] raise @types.LoadError { - 471●
ignore(column_boundaries) - 472
// 输入验证 - 473●
if elements.length() == 0 { - 474●
raise @types.LoadError::DecodeFailed( - 475
"smart_reading_order: 文档元素列表不能为空", - 476
) - 477
} - 478
let indices : Array[Int32] = [] - 479●
for i in 0..<elements.length() { - 480●
indices.push(i) - 481
} - 482
// 按列分组,然后在列内按 y 排序 - 483●
let _ = match layout_type { - 484●
LayoutType::DoubleColumn => 2 - 485●
LayoutType::TripleColumn => 3 - 486●
_ => 1 - 487
} - 488
// 简单排序:先按列索引,再按 y 坐标 - 489●
for i in 0..<indices.length() { - 490●
for j in 0..<(indices.length() - i - 1) { - 491●
let a = indices[j] - 492
let b = indices[j + 1] - 493
let should_swap = if elements[a].column_index == elements[b].column_index { - 494●
elements[a].y > elements[b].y - 495
} else { - 496●
elements[a].column_index > elements[b].column_index - 497
} - 498
if should_swap { - 499●
let temp = indices[j] - 500
indices[j] = indices[j + 1] - 501
indices[j + 1] = temp - 502
} - 503
} - 504
} - 505
indices - 506
} - 507
- 508
///| - 509
/// 从文本行构建增强版文档元素 - 510
pub fn build_enhanced_elements( - 511
lines : Array[TextLineAttributes], - 512
page_width : Int32, - 513
page_height : Int32, - 514
) -> EnhancedDocument raise @types.LoadError { - 515
// 输入验证 - 516●
if lines.length() == 0 { - 517●
raise @types.LoadError::DecodeFailed( - 518
"build_enhanced_elements: 文本行列表不能为空", - 519
) - 520
} - 521
if page_width <= 0 { - 522●
raise @types.LoadError::DecodeFailed( - 523
"build_enhanced_elements: 页面宽度必须大于0", - 524
) - 525
} - 526
if page_height <= 0 { - 527●
raise @types.LoadError::DecodeFailed( - 528
"build_enhanced_elements: 页面高度必须大于0", - 529
) - 530
} - 531
// 1. 检测布局类型 - 532●
let layout = detect_layout_type(lines, page_width, page_height) - 533
// 2. 检测页眉页脚 - 534●
let (header_bottom, footer_top) = detect_header_footer(lines, page_height) - 535
// 3. 检测列边界 - 536●
let boundaries = detect_column_boundaries(lines, page_width, layout) - 537
// 4. 计算平均字体大小 - 538
let mut total_font_size = 0.0 - 539
for line in lines { - 540●
total_font_size += line.font_size - 541
} - 542●
let avg_font_size = if lines.length() > 0 { - 543●
total_font_size / lines.length().to_double() - 544
} else { - 545○
16.0 - 546
} - 547
// 5. 计算平均 x 坐标 - 548
let mut total_x = 0 - 549
for line in lines { - 550●
total_x += line.x - 551
} - 552◐
let avg_x = if lines.length() > 0 { total_x / lines.length() } else { 0 } - 553
// 6. 构建元素 - 554
let elements : Array[EnhancedDocumentElement] = [] - 555
for line in lines { - 556
// 判断是否为页眉页脚 - 557●
let is_header = line.y + line.height <= header_bottom - 558
let is_footer = line.y >= footer_top - 559
// 判断列索引 - 560
let mut column_index = 0 - 561
let line_center = line.x + line.width / 2 - 562●
for ci in 0..<(boundaries.length() / 2) { - 563●
let col_start = boundaries[ci * 2] - 564
let col_end = boundaries[ci * 2 + 1] - 565
if line_center >= col_start && line_center <= col_end { - 566●
column_index = ci - 567
break - 568
} - 569
} - 570
// 判断元素类型 - 571●
let (is_heading, heading_level) = is_heading_line(line, avg_font_size) - 572●
let list_info = detect_list_item(line) - 573●
let is_code = is_code_block_line(line, avg_x) - 574●
let is_quote = is_quote_line(line, avg_x) - 575
let element_type = if is_header || is_footer { - 576●
MarkdownElementType::Paragraph - 577●
} else if is_heading { - 578●
match heading_level { - 579●
1 => MarkdownElementType::Heading1 - 580○
2 => MarkdownElementType::Heading2 - 581○
_ => MarkdownElementType::Heading3 - 582
} - 583●
} else if list_info.item_type != ListItemType::None { - 584●
MarkdownElementType::ListItem - 585●
} else if is_code { - 586●
MarkdownElementType::CodeBlock - 587●
} else if is_quote { - 588○
MarkdownElementType::Quote - 589
} else { - 590●
MarkdownElementType::Paragraph - 591
} - 592
let element = EnhancedDocumentElement::{ - 593
element_type, - 594
x: line.x, - 595
y: line.y, - 596
width: line.width, - 597
height: line.height, - 598
content: line.text, - 599
confidence: 0.85, - 600
font_size: line.font_size, - 601
font_weight: line.font_weight, - 602
alignment: line.alignment, - 603
list_info, - 604
column_index, - 605
indent_level: line.indent_level, - 606
is_header, - 607
is_footer, - 608
} - 609●
elements.push(element) - 610
} - 611
// 7. 智能阅读顺序 - 612●
let reading_order = smart_reading_order(elements, layout, boundaries) - 613
EnhancedDocument::{ - 614
layout_type: layout, - 615●
num_columns: match layout { - 616●
LayoutType::DoubleColumn => 2 - 617○
LayoutType::TripleColumn => 3 - 618●
_ => 1 - 619
}, - 620
page_width, - 621
page_height, - 622
header_height: header_bottom, - 623
footer_height: page_height - footer_top, - 624
body_top: header_bottom, - 625
body_bottom: footer_top, - 626
elements, - 627
reading_order, - 628
column_boundaries: boundaries, - 629
} - 630
} - 631
- 632
///| - 633
/// 增强版文档转 Markdown - 634
pub fn enhanced_document_to_markdown( - 635
doc : EnhancedDocument, - 636
include_header_footer~ : Bool = false, - 637
) -> String { - 638●
let include_flag = include_header_footer - 639
let mut md = "" - 640
// 输出布局信息(作为 HTML 注释) - 641
md = md + - 642
"<!-- 布局类型: " + - 643●
(match doc.layout_type { - 644●
LayoutType::SingleColumn => "单栏" - 645●
LayoutType::DoubleColumn => "双栏" - 646●
LayoutType::TripleColumn => "三栏" - 647●
LayoutType::MixedLayout => "混合布局" - 648●
LayoutType::UnknownLayout => "未知" - 649
}) + - 650
" -->\n\n" - 651
// 按阅读顺序输出元素 - 652
for idx in doc.reading_order { - 653●
if idx < doc.elements.length() { - 654●
let element = doc.elements[idx] - 655
// 跳过页眉页脚(除非指定包含) - 656
if !include_flag && (element.is_header || element.is_footer) { - 657●
continue - 658
} - 659
// 转换元素 - 660●
let element_md = match element.element_type { - 661●
MarkdownElementType::Title => "# " + element.content + "\n\n" - 662●
MarkdownElementType::Heading1 => "## " + element.content + "\n\n" - 663●
MarkdownElementType::Heading2 => "### " + element.content + "\n\n" - 664●
MarkdownElementType::Heading3 => "#### " + element.content + "\n\n" - 665●
MarkdownElementType::Paragraph => element.content + "\n\n" - 666●
MarkdownElementType::ListItem => { - 667
let indent = " " - 668
indent + "- " + element.content + "\n" - 669
} - 670●
MarkdownElementType::Table => element.content + "\n" - 671●
MarkdownElementType::Image => "\n\n" - 672●
MarkdownElementType::Quote => "> " + element.content + "\n\n" - 673
MarkdownElementType::CodeBlock => - 674●
"```\n" + element.content + "\n```\n\n" - 675●
MarkdownElementType::HorizontalRule => "---\n\n" - 676●
MarkdownElementType::PageBreak => "\n\n---\n\n" - 677●
MarkdownElementType::Unknown => element.content + "\n\n" - 678
} - 679
md = md + element_md - 680
} - 681
} - 682
md - 683
} - 684
- 685
///| - 686
/// 统计增强版文档元素分布 - 687
pub fn enhanced_element_distribution( - 688
doc : EnhancedDocument, - 689
) -> Array[(String, Int32)] { - 690●
let mut title_count = 0 - 691
let mut heading_count = 0 - 692
let mut paragraph_count = 0 - 693
let mut list_count = 0 - 694
let mut table_count = 0 - 695
let mut image_count = 0 - 696
let mut quote_count = 0 - 697
let mut code_count = 0 - 698
let mut header_count = 0 - 699
let mut footer_count = 0 - 700
for element in doc.elements { - 701●
match element.element_type { - 702●
MarkdownElementType::Title => title_count += 1 - 703●
MarkdownElementType::Heading1 => heading_count += 1 - 704●
MarkdownElementType::Heading2 => heading_count += 1 - 705●
MarkdownElementType::Heading3 => heading_count += 1 - 706●
MarkdownElementType::Paragraph => paragraph_count += 1 - 707●
MarkdownElementType::ListItem => list_count += 1 - 708●
MarkdownElementType::Table => table_count += 1 - 709●
MarkdownElementType::Image => image_count += 1 - 710●
MarkdownElementType::Quote => quote_count += 1 - 711●
MarkdownElementType::CodeBlock => code_count += 1 - 712●
_ => () - 713
} - 714
if element.is_header { - 715●
header_count += 1 - 716
} - 717
if element.is_footer { - 718●
footer_count += 1 - 719
} - 720
} - 721
[ - 722
("标题", title_count), - 723
("小标题", heading_count), - 724
("段落", paragraph_count), - 725
("列表", list_count), - 726
("表格", table_count), - 727
("图片", image_count), - 728
("引用", quote_count), - 729
("代码", code_count), - 730
("页眉", header_count), - 731
("页脚", footer_count), - 732
] - 733
}