https://github.com/mondeja/md-ulb-pwrap
Markdown paragraph wrapper using Unicode Line Breaking Algorithm written in Rust with Python bindings.
https://github.com/mondeja/md-ulb-pwrap
markdown python rust unicode unicode-linebreak
Last synced: 8 months ago
JSON representation
Markdown paragraph wrapper using Unicode Line Breaking Algorithm written in Rust with Python bindings.
- Host: GitHub
- URL: https://github.com/mondeja/md-ulb-pwrap
- Owner: mondeja
- License: mit
- Created: 2023-02-16T14:28:34.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-14T13:10:23.000Z (about 1 year ago)
- Last Synced: 2025-03-19T16:45:57.818Z (8 months ago)
- Topics: markdown, python, rust, unicode, unicode-linebreak
- Language: Rust
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# md-ulb-pwrap
[](https://crates.io/crates/md-ulb-pwrap) [](https://pypi.org/project/md-ulb-pwrap/)
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.
[unicode line breaking algorithm]: https://unicode.org/reports/tr14/
[container blocks]: https://spec.commonmark.org/0.30/#container-blocks
## Rust library
```bash
cargo add md-ulb-pwrap
```
````rust
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
```bash
pip install md-ulb-pwrap
```
````python
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.