Skip to content

Pipe syntax for outgoing links#125

Merged
bingryan merged 2 commits intobingryan:masterfrom
Nicendredi:pipe-syntax-for-outgoing-links
Mar 22, 2026
Merged

Pipe syntax for outgoing links#125
bingryan merged 2 commits intobingryan:masterfrom
Nicendredi:pipe-syntax-for-outgoing-links

Conversation

@Nicendredi
Copy link
Copy Markdown
Contributor

@Nicendredi Nicendredi commented Mar 2, 2026

Captures the alias of Obsidian links if it exists. e.g.:
[[My note|A special note]] becomes A special note, if removeOutgoingLinkBrackets is activated.

Tested locally on my Obsidian vault with a note containing the following types of links :

  • [[My note]] -> My note
  • [[My note|A special note]] -> A special note
  • [A special note](../folder/My%20note.md) -> [A special note](../folder/My%20note.md)

As seen in the example, there is still a problem with Markdown-style links in the original note. The rule to handle this edge case will be quite complicated to implement, if you want links to external URLs to be correctly exported, but links to Obsidian Vault files to be handled in the same way as the first two link styles.

Proposed solutions for the last edge case :

  • add "does not handle markdown-style links" in the description of the option "Remove brackets for outgoing links"
  • edit the regex to also handle markdown-style links

Summary by CodeRabbit

  • Bug Fixes
    • Improved wiki-link pattern matching to correctly handle links with optional aliases, providing more robust support for complex link syntax.

Captures the alias of Obsidian links if it exists. e.g.:
[[My note|A special note]] becomes A special note, if removeOutgoingLinkBrackets is activated.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5d8a2f82-0e40-425b-bc44-a4a5dd2e03f8

📥 Commits

Reviewing files that changed from the base of the PR and between f9ccee7 and dab2bb4.

📒 Files selected for processing (1)
  • src/config.ts

📝 Walkthrough

Walkthrough

Updated the OUTGOING_LINK_REGEXP regular expression in src/config.ts to refine wiki-link matching. The pattern now explicitly captures alias content separated by a pipe character within a named group, replacing the previous generic match-all approach with a more structured pattern.

Changes

Cohort / File(s) Summary
Configuration Update
src/config.ts
Refined OUTGOING_LINK_REGEXP to explicitly parse wiki-link aliases (e.g., [[link|alias]]) using a named capture group (?<alias>[^\]]+) instead of a generic (.*?) group, enabling more precise alias extraction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A regex refined, with care and precision,
Where aliases dance in a structured vision,
No more generic matches astray,
Just cleaner patterns to parse the day,
Wiki-links now speak with clarity's light! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Pipe syntax for outgoing links' directly matches the PR's main objective of adding support for Obsidian link aliases using pipe syntax (e.g., [[My note|A special note]]).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy reports.

@Nicendredi
Copy link
Copy Markdown
Contributor Author

Fixes #124 created as a draft until last edge case solution chosen

@Nicendredi
Copy link
Copy Markdown
Contributor Author

Nicendredi commented Mar 2, 2026

I've tested a new regex that will handle all three cases :
/(?<!!)\[\[(?:[^|\]]*\|)?(?<alias>[^\]]+)\]\]|\[(?<alt>[^\]]*)\]\((?<url>[^)]+)\)/g

If we change the replaceAll to be :
replaceAll(OUTGOING_LINK_REGEXP, (_match: string, alias: string, alt: string, url: string) => alias || alt || url)
then we get :

  • [[My note]] -> My note
  • [[My note|A special note]] -> A special note
  • [A special note](../folder/My%20note.md) -> A special note
  • [](../folder/My%20note.md) -> ../folder/My%20note.md

If the last case above is not what you want, we just need to remove the || url from the lambda function result. In that case, the link will be remove instead of being replaced, but only for that strange edge case.

@bingryan
Copy link
Copy Markdown
Owner

@Nicendredi ready for review ?

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2026

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2026

❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request

@Nicendredi Nicendredi marked this pull request as ready for review March 22, 2026 06:05
@Nicendredi
Copy link
Copy Markdown
Contributor Author

@Nicendredi ready for review ?

Hi @bingryan ,

I'm ready for review when you are (sorry for the late response)

@bingryan bingryan merged commit 8b51e64 into bingryan:master Mar 22, 2026
3 checks passed
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.

2 participants