Skip to content

Commit

Permalink
Don't wrap at / characters (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Feb 19, 2023
1 parent 79c3742 commit 6d179dc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 6 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions rust/src/pwrap.rs
Original file line number Diff line number Diff line change
@@ -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,

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6d179dc

Please sign in to comment.