fix(refactor): extend link refactoring to handle [[Title]] wiki-link syntax#1126
Merged
Conversation
…syntax Preview: FindWikiLinksForPath detects [[Title]] and [[path/hint]] patterns in page content and shows them in the affected-pages list instead of the raw route path, so users see [[Project Plan]] rather than /docs/project-plan. Apply: RewriteWikiLinks rewrites [[OldTitle]] → [[NewTitle]] on rename and [[old/path]] → [[new/path]] for path hints on rename/move, respecting code blocks and inline code spans. OldTitle/NewTitle added to RewriteRule so the rename case carries title information through to the rewrite step. Adds 11 unit tests covering both functions.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends LeafWiki’s page refactor (rename/move) link preview + apply steps to understand and rewrite [[...]] wiki-link syntax in addition to standard Markdown links, improving both the affected-pages preview display and the actual content rewrite behavior.
Changes:
- Preview: detect
[[Title]]/[[path/hint]]usage in page content and display those wiki-link forms in the affected-pages list. - Apply: rewrite
[[OldTitle]] → [[NewTitle]]during rename and[[old/path]] → [[new/path]]for path hints during rename/move, while respecting code blocks/inline code. - Plumbing: extend
RewriteRuleto optionally carry title rename data through the rewrite pipeline; add tests for wiki-link rewriting.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/wiki/pages/refactor.go | Passes page title into preview matching; applies both Markdown and wiki-link rewrites when rewriting affected pages. |
| internal/links/refactor.go | Extends rewrite rules to optionally include title rename information. |
| internal/links/link_refactor.go | Adds wiki-link rewrite + wiki-link detection helpers to the refactor engine. |
| internal/links/link_refactor_wikilinks_test.go | Adds unit tests for wiki-link rewriting and preview detection helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1. Add \s* around target in regex patterns so [[ Project Plan ]] is rewritten just like [[Project Plan]], matching the extractor's TrimSpace behaviour. 2. Promote FindWikiLinksForPath to a method on MarkdownRefactorEngine so it can use collectCandidatesAndExcludedRanges and skip fenced code blocks / inline code, making preview and apply agree on which links would actually be rewritten. 3. Expand SkipsCodeBlocks test to cover inline code spans in addition to fenced code blocks. 4. Expand TitleRenameCaseInsensitive test with whitespace variants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preview: FindWikiLinksForPath detects [[Title]] and [[path/hint]] patterns in page content and shows them in the affected-pages list instead of the raw route path, so users see [[Project Plan]] rather than /docs/project-plan.
Apply: RewriteWikiLinks rewrites [[OldTitle]] → [[NewTitle]] on rename and [[old/path]] → [[new/path]] for path hints on rename/move, respecting code blocks and inline code spans. OldTitle/NewTitle added to RewriteRule so the rename case carries title information through to the rewrite step.