File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Convert <img> tags to Markdown images for IDE/GitHub preview compatibility."""
3+ import re
4+ from pathlib import Path
5+
6+ DOCS = Path (__file__ ).resolve ().parents [1 ] / "docs"
7+
8+ IMG = re .compile (
9+ r'<img src="\./screenshots/([^"]+)" alt="([^"]*)"(?:\s+width="\d+")?\s*/>\s*\n*' ,
10+ re .MULTILINE ,
11+ )
12+
13+
14+ def convert (path : Path ) -> int :
15+ text = path .read_text (encoding = "utf-8" )
16+ n = 0
17+
18+ def repl (m : re .Match ) -> str :
19+ nonlocal n
20+ n += 1
21+ file , alt = m .group (1 ), m .group (2 ).strip () or m .group (1 )
22+ return f"\n \n "
23+
24+ text = IMG .sub (repl , text )
25+ path .write_text (text , encoding = "utf-8" , newline = "\n " )
26+ return n
27+
28+
29+ def main () -> None :
30+ for name in ("USER_MANUAL.md" , "INSTALL.md" ):
31+ p = DOCS / name
32+ if p .is_file ():
33+ print (f"{ name } : converted { convert (p )} images" )
34+
35+
36+ if __name__ == "__main__" :
37+ main ()
You can’t perform that action at this time.
0 commit comments