#paragraph #markdown #unicode #breaking #line #wrapper #algorithm

md-ulb-pwrap

Markdown paragraph wrapper using Unicode Line Breaking Algorithm

4 releases

0.1.0 Aug 10, 2023
0.0.3 Feb 19, 2023
0.0.2 Feb 19, 2023
0.0.1 Feb 16, 2023

#1070 in Text processing

27 downloads per month

BSD-3-Clause

21KB
547 lines

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.

Dependencies

~78KB