forked from swaroopch/byte-of-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_nbsp.py
More file actions
33 lines (25 loc) · 880 Bytes
/
Copy pathfix_nbsp.py
File metadata and controls
33 lines (25 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
"""Replace non-breaking spaces (U+00A0) with ordinary spaces in the markdown.
Non-breaking spaces are invisible in most editors but break literal text
searches and can render oddly. They creep in when text is pasted from word
processors or web pages.
Run from the repo root: uv run fix_nbsp.py
"""
import sys
from pathlib import Path
ROOT = Path(__file__).parent / "docs"
NBSP = " "
def main():
changed = 0
for path in sorted(ROOT.glob("*.md")):
text = path.read_text(encoding="utf-8")
if NBSP not in text:
continue
count = text.count(NBSP)
path.write_text(text.replace(NBSP, " "), encoding="utf-8")
print(f"{path.name}: replaced {count} non-breaking space(s)")
changed += 1
print(f"\n{changed} file(s) updated.")
return 0
if __name__ == "__main__":
sys.exit(main())