Skip to content

Commit 62763a8

Browse files
committed
Fix custom id in headers
1 parent f485e4d commit 62763a8

6 files changed

Lines changed: 21 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "writeadoc"
3-
version = "0.15.0"
3+
version = "0.16.0"
44
description = "Focus on your content and let WriteADoc take care of the rest"
55
authors = [
66
{name = "Juan Pablo Scaletti", email = "juanpablo@jpscaletti.com"},

src/writeadoc/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ def warn(filename: str, lineno: int, msg: str) -> None:
408408
if re.match(r"^(https?://|mailto:|tel:)", url):
409409
continue
410410

411+
# Skip LLM.txt references
412+
if url.startswith("/LLM.txt"):
413+
continue
414+
411415
# Resolve relative URLs against the page's own URL
412416
if not url.startswith("/"):
413417
base = page.url.rstrip("/")
@@ -441,6 +445,9 @@ def warn(filename: str, lineno: int, msg: str) -> None:
441445

442446
warn(filename, lineno, f"broken link: {raw_url}")
443447

448+
if has_warnings:
449+
print()
450+
444451
def _symlink_assets(self) -> None:
445452
if not self.assets_dir.exists():
446453
return

src/writeadoc/md/render.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def slugify(value: str, separator: str = "-", unicode: bool = True) -> str:
6868

6969

7070
def heading_id(token: dict[str, t.Any], index: int) -> str:
71+
if "id" in token.get("attrs", {}):
72+
return token["attrs"]["id"]
7173
value = RX_ATTRS_IN_HEADER.sub("", token["text"]).strip()
7274
return slugify(value)
7375

src/writeadoc/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def start_server(build_folder: str) -> None:
5858
port = 8000
5959
handler = partial(SimpleHTTPRequestHandler, directory=build_folder)
6060
server = ThreadingHTTPServer(("0.0.0.0", port), handler)
61-
print(f"Serving docs on http://localhost:{port}/")
61+
print(f"Serving docs on http://localhost:{port}/\n")
6262
try:
6363
server.serve_forever()
6464
except KeyboardInterrupt:

tests/md/test_attrs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@
7474
"""
7575
),
7676

77+
( # heading with custom id
78+
"""
79+
## Hello
80+
{ #world }
81+
""",
82+
"""<h2 id="world">Hello</h2>
83+
"""
84+
),
85+
7786
( # thematic_break
7887
"""
7988
----

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)