Skip to content

Commit 042ea30

Browse files
committed
feat: use unicode-width if eabled
1 parent 3f2d66b commit 042ea30

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

mdast_util_to_markdown/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[dependencies]
22
markdown = { path = "../", version = "1.0.0" }
33
regex = { version = "1" }
4-
unicode-width = { version = "0.1" }
4+
unicode-width = { version = "0.1", optional = true }
5+
6+
[features]
7+
default = []
8+
unicode-width = ["dep:unicode-width"]
59

610
[dev-dependencies]
711
pretty_assertions = { workspace = true }

mdast_util_to_markdown/src/handle/table.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,18 @@ fn collect_text_content(nodes: &[Node], result: &mut String) {
199199
}
200200
}
201201

202-
/// Get the display width of a string, accounting for Unicode
202+
/// Get the display width of a string, accounting for Unicode when feature is enabled
203203
fn display_width(s: &str) -> usize {
204-
use unicode_width::UnicodeWidthStr;
205-
UnicodeWidthStr::width(s)
204+
#[cfg(feature = "unicode-width")]
205+
{
206+
use unicode_width::UnicodeWidthStr;
207+
UnicodeWidthStr::width(s)
208+
}
209+
#[cfg(not(feature = "unicode-width"))]
210+
{
211+
// Use character count instead of byte count for better default behavior
212+
s.chars().count()
213+
}
206214
}
207215

208216
/// Render the delimiter row with alignment markers

0 commit comments

Comments
 (0)