Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 1.62 KB

README.md

File metadata and controls

62 lines (45 loc) · 1.62 KB

md-ulb-pwrap

Crate PyPI

Markdown paragraph wrapper using Unicode Line Breaking Algorithm.

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.