Skip to content

Add extract_link_definitions() for reference-style links#164

Merged
nesono merged 1 commit intomainfrom
feat/extract-link-definitions
Feb 11, 2026
Merged

Add extract_link_definitions() for reference-style links#164
nesono merged 1 commit intomainfrom
feat/extract-link-definitions

Conversation

@nesono
Copy link
Copy Markdown
Owner

@nesono nesono commented Feb 11, 2026

Summary

Add extract_link_definitions() function to parse reference-style link definitions from markdown text. This is the foundation for upcoming reference-style link support (https://www.markdownguide.org/basic-syntax/#reference-style-links).

Implementation Summary

Added new function extract_link_definitions(text: str) -> dict[str, str] to fire/starlark/markdown_common.py that:

  • Parses markdown reference-style link definitions in the format [label]: url
  • Uses multiline regex to match definitions at line start
  • Returns dictionary mapping reference labels to URLs
  • Handles whitespace, complex URLs (with queries/anchors), and duplicate labels (last wins)

The function is not yet integrated into business logic - it's pure infrastructure that will be activated in a future PR when we add link resolution.

Testing

Added comprehensive test class TestExtractLinkDefinitions with 11 test cases:

  • Single/multiple definitions (numbered and named labels)
  • Empty text and no definitions
  • Whitespace handling
  • Duplicate labels (verifies last definition wins)
  • Complex URLs with query parameters and anchors
  • Indented definitions (verifies they're not matched)
  • Mixed content with definitions interspersed

All tests pass:

  • bazel test //fire/starlark:markdown_common_test
  • All existing tests still pass ✓

🤖 Generated with Claude Code

Foundation for markdown reference-style link support. Adds function to
parse link definitions in the format "[label]: url" from markdown text.
Not yet integrated into business logic.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@nesono nesono enabled auto-merge (squash) February 11, 2026 18:02
@nesono nesono merged commit e36834e into main Feb 11, 2026
9 checks passed
@nesono nesono deleted the feat/extract-link-definitions branch February 11, 2026 18:05
nesono added a commit that referenced this pull request Feb 11, 2026
### Summary

Activate reference-style link support by integrating
`resolve_reference_links()` into the cross-reference extraction flow.
Reference-style links in requirement bodies are now automatically
converted to inline links during validation.

### Implementation Summary

Modified `extract_markdown_references()` in
`fire/starlark/validate_cross_references.py` to:
- Call `markdown_common.resolve_reference_links()` before extracting
references
- Wrap in try/except to handle undefined references gracefully
- Continue with original text if undefined references are found (they
won't match patterns anyway)

This is a minimal integration point that activates all the
infrastructure built in PRs #164, #165, and #166.

**Example:** Requirements can now write:
```markdown
See [REQ-VEL-001][1] for velocity limits and [@braking_distance_table][2].

[1]: /examples/requirements/velocity_requirements.sysreq.md?version=2#REQ-VEL-001
[2]: /examples/vehicle_params.yaml?version=1#braking_distance_table
```

And it will be validated as if it were written with inline links.

### Testing

Verified integration works:
- ✓ `bazel test //fire/starlark:extract_source_traceability_test` passes
- ✓ `bazel build //examples/brake_control:brake_controller_requirements`
succeeds
- ✓ All existing requirement validation still works
- ✓ No breaking changes to existing inline link syntax

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant