1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use minimad::{Line, TableRule};
use crate::composite::FmtComposite;
use crate::skin::MadSkin;
use crate::tbl::{FmtTableRow, FmtTableRule, RelativePosition};
pub enum FmtLine<'s> {
Normal(FmtComposite<'s>),
TableRow(FmtTableRow<'s>),
TableRule(FmtTableRule),
HorizontalRule,
}
impl<'s> FmtLine<'s> {
pub fn from(mline: Line<'s>, skin: &MadSkin) -> Self {
match mline {
Line::Normal(composite) => FmtLine::Normal(FmtComposite::from(composite, skin)),
Line::TableRow(table_row) => FmtLine::TableRow(FmtTableRow::from(table_row, skin)),
Line::TableRule(TableRule { cells }) => FmtLine::TableRule(FmtTableRule {
position: RelativePosition::Other,
widths: Vec::new(),
aligns: cells,
}),
Line::HorizontalRule => FmtLine::HorizontalRule,
Line::CodeFence(..) => FmtLine::HorizontalRule,
}
}
pub fn visible_length(&self) -> usize {
match self {
FmtLine::Normal(composite) => composite.visible_length,
FmtLine::TableRow(row) => row.cells.iter().fold(0, |s, c| s + c.visible_length),
FmtLine::TableRule(rule) => 1 + rule.widths.iter().fold(0, |s, w| s + w + 1),
FmtLine::HorizontalRule => 0,
}
}
}