Skip to content

Commit a93d759

Browse files
committed
feat: improve sentence wrapper and fix naming issues
1 parent b797274 commit a93d759

19 files changed

Lines changed: 607 additions & 234 deletions

.copier-answers.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ author_email: dev.act.kyle@gmail.com
88
author_name: Kyle King
99
author_username: kyleking
1010
copyright_date: '2025'
11-
package_name_kebab: mdformat-mdformat-mdsf
12-
plugin_name: mdformat_mdsf
11+
package_name_kebab: mdformat-mdslw
12+
plugin_name: mdslw
1313
repository_namespace: kyleking
1414
repository_provider: https://github.com
15-
repository_url: https://github.com/kyleking/mdformat-mdformat-mdsf
15+
repository_url: https://github.com/kyleking/mdformat-mdslw
1616
sync_admon_factories: false
1717

AGENTS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The package implements mdformat's plugin interface with up to four key exports i
5757

5858
### Core Components
5959

60-
**mdformat_mdformat_mdsf/plugin.py**
60+
**mdformat_mdslw/plugin.py**
6161

6262
- Entry point that configures the mdformat plugin, registers all mdit_plugins, defines custom renders, and handles CLI configuration options
6363

@@ -68,10 +68,10 @@ Configuration can be passed via:
6868
1. Example CLI arguments: `--cli-argument`
6969
1. Example TOML config file (`.mdformat.toml`):
7070
```toml
71-
[plugin.mdformat_mdsf]
71+
[plugin.mdslw]
7272
cli_argument = true
7373
```
74-
1. API: `mdformat.text(content, extensions={"mdformat_mdsf"}, options={...})`
74+
1. API: `mdformat.text(content, extensions={"mdslw"}, options={...})`
7575

7676
### Testing Strategy
7777

@@ -91,4 +91,4 @@ Configuration can be passed via:
9191
- Uses `tox` for test automation with multiple Python versions (3.10, 3.14)
9292
- Pre-commit is configured but the project now uses `prek` (faster alternative)
9393
- Python 3.10+ is required (see `requires-python` in `pyproject.toml`)
94-
- Version is defined in `mdformat_mdformat_mdsf/__init__.py` as `__version__`
94+
- Version is defined in `mdformat_mdslw/__init__.py` as `__version__`

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ This project uses [PyPI Trusted Publishers](https://docs.pypi.org/trusted-publis
8080

8181
Before publishing for the first time, you need to configure Trusted Publishing on PyPI:
8282

83-
1. Go to your project's page on PyPI: `https://pypi.org/manage/project/mdformat_mdformat_mdsf/settings/publishing/`
83+
1. Go to your project's page on PyPI: `https://pypi.org/manage/project/mdformat_mdslw/settings/publishing/`
8484
- If the project doesn't exist yet, go to [PyPI's publishing page](https://pypi.org/manage/account/publishing) to add a "pending" publisher
8585
1. Add a new Trusted Publisher with these settings:
86-
- **PyPI Project Name**: `mdformat_mdformat_mdsf`
86+
- **PyPI Project Name**: `mdformat_mdslw`
8787
- **Owner**: `kyleking`
88-
- **Repository name**: `mdformat-mdformat-mdsf`
88+
- **Repository name**: `mdformat-mdslw`
8989
- **Workflow name**: `tests.yml` (`.github/workflows/tests.yml`)
9090
- **Environment name**: `pypi`
9191
1. Configure the GitHub Environment:
@@ -95,7 +95,7 @@ Before publishing for the first time, you need to configure Trusted Publishing o
9595

9696
### Publishing a Release
9797

98-
Use `commitizen` to automatically bump versions (in `pyproject.toml` and `mdformat_mdformat_mdsf/__init__.py`) and create a commit with tag:
98+
Use `commitizen` to automatically bump versions (in `pyproject.toml` and `mdformat_mdslw/__init__.py`) and create a commit with tag:
9999

100100
```sh
101101
# Dry run to preview the version bump

README.md

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1-
# mdformat-mdformat-mdsf
1+
# mdformat-mdslw
22

33
[![Build Status][ci-badge]][ci-link] [![PyPI version][pypi-badge]][pypi-link]
44

5-
An [mdformat](https://github.com/executablebooks/mdformat) plugin for `<placeholder>`
5+
An [mdformat](https://github.com/executablebooks/mdformat) plugin for [mdslw](https://github.com/razziel89/mdslw)-style sentence wrapping.
6+
7+
This plugin wraps markdown text by inserting line breaks after sentence-ending punctuation, making diffs cleaner and easier to review.
8+
9+
## Features
10+
11+
- Wrap sentences at configurable punctuation marks (default: `.!?:`)
12+
- Optional maximum line width enforcement
13+
- Preserves markdown formatting (bold, italic, links, etc.)
14+
- Handles edge cases: quoted text, parentheses, brackets
615

716
## `mdformat` Usage
817

918
Add this package wherever you use `mdformat` and the plugin will be auto-recognized. No additional configuration necessary. See [additional information on `mdformat` plugins here](https://mdformat.readthedocs.io/en/stable/users/plugins.html)
1019

20+
### CLI
21+
22+
```sh
23+
mdformat --wrap-sentences document.md
24+
```
25+
26+
#### Options
27+
28+
- `--wrap-sentences`: Enable sentence wrapping (required to activate the plugin)
29+
- `--sentence-markers TEXT`: Characters that mark sentence endings (default: `.!?:`)
30+
- `--max-line-width INTEGER`: Maximum line width for wrapping (default: 80, 0 to disable)
31+
32+
### Configuration File
33+
34+
Create a `.mdformat.toml` file in your project root:
35+
36+
```toml
37+
[plugin.mdslw]
38+
wrap_sentences = true
39+
sentence_markers = ".!?:"
40+
max_line_width = 80
41+
```
42+
1143
### pre-commit / prek
1244

1345
```yaml
@@ -17,46 +49,65 @@ repos:
1749
hooks:
1850
- id: mdformat
1951
additional_dependencies:
20-
- mdformat-mdformat-mdsf
52+
- mdformat-mdslw
53+
args: [--wrap-sentences]
2154
```
2255
2356
### uvx
2457
2558
```sh
26-
uvx --with mdformat-mdformat-mdsf mdformat
59+
uvx --with mdformat-mdslw mdformat --wrap-sentences document.md
2760
```
2861

2962
Or with pipx:
3063

3164
```sh
3265
pipx install mdformat
33-
pipx inject mdformat mdformat-mdformat-mdsf
66+
pipx inject mdformat mdformat-mdslw
67+
mdformat --wrap-sentences document.md
3468
```
3569

36-
## HTML Rendering
70+
### Python API
3771

38-
To generate HTML output, `mdformat_mdsf_plugin` can be imported from `mdit_plugins`. For more guidance on `MarkdownIt`, see the docs: <https://markdown-it-py.readthedocs.io/en/latest/using.html#the-parser>
72+
```python
73+
import mdformat
3974

40-
```py
41-
from markdown_it import MarkdownIt
75+
text = """
76+
This is a test. It has multiple sentences! Does it work?
77+
"""
4278

43-
from mdformat_mdformat_mdsf.mdit_plugins import mdformat_mdsf_plugin
79+
# Enable sentence wrapping
80+
result = mdformat.text(text, extensions={"mdslw"}, options={"wrap_sentences": True})
81+
82+
print(result)
83+
# Output:
84+
# This is a test.
85+
# It has multiple sentences!
86+
# Does it work?
87+
```
88+
89+
## Example
90+
91+
**Input:**
92+
93+
```markdown
94+
This is a long sentence. It contains multiple clauses! Does it work? Yes it does.
95+
```
4496

45-
md = MarkdownIt()
46-
md.use(mdformat_mdsf_plugin)
97+
**Output (with `--wrap-sentences`):**
4798

48-
text = "... markdown example ..."
49-
md.render(text)
50-
# <div>
51-
#
52-
# </div>
99+
```markdown
100+
This is a long sentence.
101+
It contains multiple clauses!
102+
Does it work?
103+
Yes it does.
53104
```
54105

55106
## Contributing
56107

57-
See [CONTRIBUTING.md](https://github.com/kyleking/mdformat-mdformat-mdsf/blob/main/CONTRIBUTING.md)
108+
See [CONTRIBUTING.md](https://github.com/kyleking/mdformat-mdslw/blob/main/CONTRIBUTING.md)
58109

59-
[ci-badge]: https://github.com/kyleking/mdformat-mdformat-mdsf/actions/workflows/tests.yml/badge.svg?branch=main
60-
[ci-link]: https://github.com/kyleking/mdformat-mdformat-mdsf/actions?query=workflow%3ACI+branch%3Amain+event%3Apush
61-
[pypi-badge]: https://img.shields.io/pypi/v/mdformat-mdformat-mdsf.svg
62-
[pypi-link]: https://pypi.org/project/mdformat-mdformat-mdsf
110+
[ci-badge]: https://github.com/kyleking/mdformat-mdslw/actions/workflows/tests.yml/badge.svg?branch=main
111+
[ci-link]: https://github.com/kyleking/mdformat-mdslw/actions?query=workflow%3ACI+branch%3Amain+event%3Apush
112+
[pypi-badge]: https://img.shields.io/pypi/v/mdformat-mdslw.svg
113+
[pypi-link]: https://pypi.org/project/mdformat-mdslw

mdformat_mdformat_mdsf/_helpers.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

mdformat_mdformat_mdsf/_sentence_wrapper.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

mdformat_mdslw/_helpers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""General Helpers for configuration management."""
2+
3+
from __future__ import annotations
4+
5+
from collections.abc import Mapping
6+
from typing import Any, TypeAlias
7+
8+
from . import __plugin_name__
9+
10+
ContextOptions: TypeAlias = Mapping[str, Any]
11+
12+
13+
def get_conf(options: ContextOptions, key: str) -> bool | str | int | None:
14+
"""Read setting from mdformat configuration Context.
15+
16+
Configuration can be provided via:
17+
1. API call: mdformat.text(..., options={key: value})
18+
2. CLI/TOML: stored in options["mdformat"]["plugin"]["mdslw"][key]
19+
20+
Args:
21+
options: Configuration options from mdformat rendering context
22+
key: Configuration key to retrieve
23+
24+
Returns:
25+
Configuration value (bool, str, int, or None if not found)
26+
27+
"""
28+
if (api := options["mdformat"].get(key)) is not None:
29+
return api # From API
30+
return (
31+
options["mdformat"].get("plugin", {}).get(__plugin_name__, {}).get(key)
32+
) # from cli_or_toml

0 commit comments

Comments
 (0)