Skip to content

Commit bd3afbc

Browse files
authored
Fix Weave TypeScript SDK generation script to fix readme anchor links in extracted functions and type aliases (#1944)
## Description Fix Weave TypeScript SDK generation script to fix readme anchor links in extracted functions and type aliases This was intended to be part of #1941 but somehow I reverted it.
1 parent 64a0369 commit bd3afbc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

scripts/reference-generation/weave/generate_typescript_sdk_docs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ def extract_members_to_separate_files(docs_path):
339339
func_content = func_content.replace('./typescript-sdk/type-aliases/', '../type-aliases/')
340340
func_content = func_content.replace('./typescript-sdk/functions/', './')
341341

342+
# Fix anchor links to readme/landing page
343+
# Links like (./readme#anchor) need to point to type-aliases (which is where they're extracted to)
344+
func_content = re.sub(r'\]\(\./readme#([^)]+)\)', r'](../type-aliases/\1)', func_content)
345+
func_content = re.sub(r'\]\(readme#([^)]+)\)', r'](../type-aliases/\1)', func_content)
346+
342347
# Fix TypeDoc-generated anchor links like (typescript-sdk#op) -> (../type-aliases/op)
343348
func_content = re.sub(r'\]\(typescript-sdk#([^)]+)\)', r'](../type-aliases/\1)', func_content)
344349

@@ -402,6 +407,11 @@ def extract_members_to_separate_files(docs_path):
402407
alias_content = alias_content.replace('./typescript-sdk/functions/', '../functions/')
403408
alias_content = alias_content.replace('./typescript-sdk/type-aliases/', './')
404409

410+
# Fix anchor links to readme/landing page
411+
# Links like (./readme#anchor) stay within type-aliases (self-referential)
412+
alias_content = re.sub(r'\]\(\./readme#([^)]+)\)', lambda m: f'](./{m.group(1).lower()})', alias_content)
413+
alias_content = re.sub(r'\]\(readme#([^)]+)\)', lambda m: f'](./{m.group(1).lower()})', alias_content)
414+
405415
# Fix TypeDoc-generated anchor links like (typescript-sdk#op) -> (./op)
406416
alias_content = re.sub(r'\]\(typescript-sdk#([^)]+)\)', lambda m: f'](./{m.group(1).lower()})', alias_content)
407417

0 commit comments

Comments
 (0)