From 6d179dccfe989ff1946d830ffc292dd19e563254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sun, 19 Feb 2023 15:36:11 +0100 Subject: [PATCH] Don't wrap at `/` characters (#3) --- python/Cargo.lock | 4 ++-- python/Cargo.toml | 2 +- rust/Cargo.lock | 2 +- rust/Cargo.toml | 2 +- rust/src/lib.rs | 6 ++++++ rust/src/pwrap.rs | 8 +++++--- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/Cargo.lock b/python/Cargo.lock index 714fada..25fdb8c 100644 --- a/python/Cargo.lock +++ b/python/Cargo.lock @@ -84,7 +84,7 @@ dependencies = [ [[package]] name = "md-ulb-pwrap" -version = "0.0.2" +version = "0.0.3" dependencies = [ "unicode-linebreak", ] @@ -144,7 +144,7 @@ dependencies = [ [[package]] name = "py-md-ulb-pwrap" -version = "0.0.2" +version = "0.0.3" dependencies = [ "md-ulb-pwrap", "pyo3", diff --git a/python/Cargo.toml b/python/Cargo.toml index f639df8..ee7802d 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "py-md-ulb-pwrap" -version = "0.0.2" +version = "0.0.3" edition = "2021" description = "Python bindings for Rust crate md-ulb-pwrap." readme = "../README.md" diff --git a/rust/Cargo.lock b/rust/Cargo.lock index e8310a2..852f463 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -157,7 +157,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "md-ulb-pwrap" -version = "0.0.2" +version = "0.0.3" dependencies = [ "rstest", "unicode-linebreak", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0f9ea59..4b214f0 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "md-ulb-pwrap" -version = "0.0.2" +version = "0.0.3" edition = "2021" description = "Markdown paragraph wrapper using Unicode Line Breaking Algorithm." license = "BSD-3-Clause" diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8873e11..2d1785c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -232,6 +232,12 @@ mod tests { 4, "[link\ntext](link\\\ndestination\n'link\ntitle')", )] + #[case( + // Don't wrap on '/' character + &"[foo bar](https://foo.bar/baz/qux/fox)", + 1, + "[foo\nbar](https://foo.bar/baz/qux/fox)", + )] #[case( // hard line breaks &"hard \nline break", diff --git a/rust/src/pwrap.rs b/rust/src/pwrap.rs index d76bcec..5ac1400 100644 --- a/rust/src/pwrap.rs +++ b/rust/src/pwrap.rs @@ -1,7 +1,8 @@ use crate::parser::MarkdownWrapOpportunitiesParser; - use unicode_linebreak::{linebreaks, BreakOpportunity, BreakOpportunity::Mandatory}; +static CHARACTERS_TO_SKIP_WRAP: [char; 2] = ['-', '/']; + pub struct MarkdownParagraphWrapper { width: usize, @@ -81,8 +82,9 @@ impl MarkdownParagraphWrapper { let (_, (_, prev_character)) = self.characters[ self.codespan_parser.characters_i - 1 ]; - if character == '-' || prev_character == '-' { - break; + if CHARACTERS_TO_SKIP_WRAP.contains(&character) || + CHARACTERS_TO_SKIP_WRAP.contains(&prev_character) { + break } self.codespan_parser.backup_state(); self.codespan_parser.parse_character(character);