|
10 | 10 | page id (e.g. "{#2-2-settings}" on page 2.2.-Settings), and cross-page links |
11 | 11 | are rewritten to same-document anchors pointing at those ids. |
12 | 12 |
|
| 13 | +Image paths are rewritten from site-root-absolute (/images/...) to a path |
| 14 | +relative to the print page URL (/<lang>/print/ -> ../../images/...). |
| 15 | +
|
13 | 16 | Usage: |
14 | 17 | python scripts/export_docs.py # -> print.md for every multi-page language |
15 | 18 | python scripts/export_docs.py fr # -> docs/doc/fr/print.md only |
|
34 | 37 | SITE_LINK_RE = re.compile(r"\[([^]]+)]\(/[^)]*\)") |
35 | 38 | DOC_LINK_RE = re.compile( |
36 | 39 | r"\[([^]]+)]\(([^)#\s]+?)(?:\.md)?(?:/)?(?:#([^)]*))?\)") |
| 40 | +# Root-absolute image paths (/images/...) become relative to /<lang>/print/. |
| 41 | +IMAGE_RE = re.compile(r"(\!\[[^]]*]\()(/?images/)") |
37 | 42 |
|
38 | 43 |
|
39 | 44 | def load_config() -> dict: |
@@ -192,9 +197,10 @@ def add_heading_ids(text: str, pid: str) -> str: |
192 | 197 |
|
193 | 198 |
|
194 | 199 | def page_to_markdown(path: Path, anchors: dict[tuple[str, str | None], str]) -> str: |
195 | | - """Read one page: strip front-matter, rewrite links, add heading ids.""" |
| 200 | + """Read one page: strip front-matter, rewrite images and links, add ids.""" |
196 | 201 | text = path.read_text(encoding="utf-8") |
197 | 202 | text = FRONT_MATTER_RE.sub("", text, count=1) |
| 203 | + text = IMAGE_RE.sub(r"\1../../images/", text) |
198 | 204 | text = rewrite_links(text, anchors) |
199 | 205 | text = add_heading_ids(text, page_id(path)) |
200 | 206 | return text.strip() |
|
0 commit comments