Skip to content

mondeja/md-ulb-pwrap

Repository files navigation

md-ulb-pwrap

Crate PyPI

Markdown paragraph wrapper using Unicode Line Breaking Algorithm. Includes a Rust library with Python bindings.

Wrap a Markdown paragraph using a maximum desired width. Only works for paragraphs that don't contain other container blocks. Respects the prohibition against wrapping text inside inline code blocks and links.

Rust library

cargo add md-ulb-pwrap
use md_ulb_pwrap::ulb_wrap_paragraph;

assert_eq!(
    ulb_wrap_paragraph(
        &"aaa ``` ``  ` a b c ``` ccc",
        3,
        3,
    ),
    "aaa\n``` ``  ` a b c ```\nccc",
);

Python bindings

pip install md-ulb-pwrap
from md_ulb_pwrap import ulb_wrap_paragraph

markdown = "aaa ``` ``  ` a b c ``` ccc"
expected_result = "aaa\n``` ``  ` a b c ```\nccc"
assert ulb_wrap_paragraph(markdown, 3, 3) == expected_result

Reference

ulb_wrap_paragraph(text: str, width: int, first_line_width: int) -> str

  • text (str): The text to wrap.
  • width (int): The maximum width of the lines after the first.
  • first_line_width (int): The maximum width of the first line.

Returns (str): The wrapped text.

About

Markdown paragraph wrapper using Unicode Line Breaking Algorithm written in Rust with Python bindings.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published