Drop break hints and discretionary hyphens
This commit is contained in:
1 parent
6c771e0820
commit
ca433d256d
3 files changed
+23
-4
No files matched your search
+20
-1
@@ -6904,7 +6904,7 @@ fn split_color_runs(
|
||||
}
|
||||
|
||||
fn strip_noop_commands(text: &str) -> String {
|
||||
const COMMANDS: [&str; 10] = [
|
||||
const COMMANDS: [&str; 14] = [
|
||||
"\\protect",
|
||||
"\\relax",
|
||||
"\\ignorespaces",
|
||||
@@ -6915,6 +6915,10 @@ fn strip_noop_commands(text: &str) -> String {
|
||||
"\\fussy",
|
||||
"\\phantomsection",
|
||||
"\\leavevmode",
|
||||
"\\linebreak",
|
||||
"\\nolinebreak",
|
||||
"\\pagebreak",
|
||||
"\\nopagebreak",
|
||||
];
|
||||
let mut out = String::new();
|
||||
let mut index = 0;
|
||||
@@ -6937,6 +6941,15 @@ fn strip_noop_commands(text: &str) -> String {
|
||||
}
|
||||
if let Some(length) = matched {
|
||||
index += length;
|
||||
if let Some(after) = text[index..].trim_start().strip_prefix('[') {
|
||||
if let Some(close) = after.find(']') {
|
||||
index = text.len() - after.len() + close + 1;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if rest.starts_with("\\-") {
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
let Some(character) = rest.chars().next() else {
|
||||
@@ -13412,6 +13425,12 @@ A definition.
|
||||
assert!(!preview.contains("textbraceleft"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn break_hints_and_discretionary_hyphens_vanish() {
|
||||
let text = strip_noop_commands("First\\linebreak[4] Second \\- co\\-op.");
|
||||
assert_eq!(text, "First Second coop.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noop_commands_are_dropped() {
|
||||
let preview = preview_json("A \\protect B \\relax C \\ignorespaces D \\phantomsection E.")
|
||||
|
||||
Reference in new issue
Block a user