Respect combined float placement options and bold description terms

This commit is contained in:
gloamxun committed 2026-10-25 02:32:11 +08:00
1 parent 6d0794ef3a
commit 87d5f55be2
4 files changed
+42 -13

No files matched your search

+38 -9
View File
@@ -2591,13 +2591,14 @@ fn embedded_table(inner: &str) -> Option<usize> {
}
fn figure_placement(spec: &str) -> FloatPlacement {
for option in spec.chars() {
match option {
'b' => return FloatPlacement::Bottom,
'h' => return FloatPlacement::Here,
't' => return FloatPlacement::Top,
_ => {}
}
if spec.chars().any(|option| matches!(option, 'h' | 'H')) {
return FloatPlacement::Here;
}
if spec.contains('t') {
return FloatPlacement::Top;
}
if spec.contains('b') {
return FloatPlacement::Bottom;
}
FloatPlacement::Top
}
@@ -3323,7 +3324,7 @@ fn list_blocks(
if term.is_empty() {
(String::new(), rest)
} else {
(format!("{term} — "), rest)
(format!("\\textbf{{{term}}} — "), rest)
}
}
"enumerate" => {
@@ -6753,6 +6754,25 @@ mod source_tests {
}));
}
#[test]
fn float_placement_options_follow_the_spec() {
for (spec, placement) in [
("[htbp]", FloatPlacement::Here),
("[!t]", FloatPlacement::Top),
("[b]", FloatPlacement::Bottom),
("[H]", FloatPlacement::Here),
("[]", FloatPlacement::Top),
] {
let source = format!("\\begin{{figure}}{}\n\\caption{{A}}\n\\end{{figure}}", spec);
let blocks = paragraphs(&source).expect("paragraphs");
assert_eq!(
blocks[0].float.as_ref().expect("float").placement,
placement,
"spec {spec}"
);
}
}
#[test]
fn figures_become_float_units() {
let source = "\\begin{figure}[h]\n\\caption{A caption}\\label{fig:a}\n\\end{figure}";
@@ -7547,10 +7567,19 @@ See \ref{fig:a} and \ref{tab:b}.";
let source = "\\begin{description}\n\\item[Term] Definition\n\\end{description}";
let blocks = paragraphs(source).unwrap();
assert_eq!(blocks.len(), 1);
assert_eq!(blocks[0].text, "Term — Definition");
assert_eq!(blocks[0].text, "\\textbf{Term} — Definition");
assert_eq!(blocks[0].left_skip, 12);
}
#[test]
fn description_terms_are_bold() {
let json =
preview_json("\\begin{description}\n\\item[Term] Definition\n\\end{description}")
.expect("preview");
assert!(json.contains(r#"font-weight=\"bold\""#), "{json}");
assert!(json.contains(">T</text>"), "{json}");
}
#[test]
fn newif_definitions_default_to_false() {
let source = "\\newif\\ifdraft\n\\ifdraft Draft\\else Final\\fi";