Skip to content

Added collapse relative links functionality - #585

Merged
Brian Harney (bharney0) merged 5 commits into
microsoft:masterfrom
IEvangelist:collapse-rel-links
May 19, 2020
Merged

Brian Harney (bharney0) merged 5 commits into
microsoft:masterfrom
IEvangelist:collapse-rel-links

Conversation

@IEvangelist

@IEvangelist David Pine (IEvangelist) commented May 19, 2020 •

Copy link
Copy Markdown
Member

Added collapse relative links functionality. Inspired by pull requests such as this:

Automate this functionality with the click of a button, I hope that Next Turn (@NextTurn) will appreciate this addition 🎉

collapse-rel-links

Validated the following link examples:

[Link 1](http://microsoft.com)
[Link 2](https://microsoft.com)
[Link 3](link.md)
[Link 4](/link.md)
[Link 5](./link.md)
[Link 6](../link.md)
[Link 7](~/link.md)
[Link 8](../../link.md?q=1)
[Link 9](../../link.md#bookmark)
[Link 10](../../../link.md?q=1#bookmark)

Using this JavaScript RegExp:

linkRegExp: RegExp = /\]\((?<path>[^http?|~].+?)(?<query>\?.+?)?(?<hash>#.+?)?\)/gm;

@nxtn

Next Turn (nxtn) commented May 19, 2020 •

Copy link
Copy Markdown
Contributor

David Pine (@IEvangelist) Thanks for the feature! I appreciate it a lot.

I hope this could add an option to configure the path style. The .NET docs team used to prefer to prefix subdirectories with ./ (e.g. [](./dir/file.md)).

Some potential problems with common cases:

  • Does it work with anchors (e.g. [](../dir/file.md#anchor))?
  • What would be the expected behavior for ~/ links that can be collapsed as well?

@IEvangelist

David Pine (IEvangelist) commented May 19, 2020 •

Copy link
Copy Markdown
Member Author

Ah, these are good observations - and things that I'll need to account for. I do not currently handle query strings or bookmarks, those should be easy to add. As for the style, I'm on the .NET docs team myself and I can tell you that the preference is not a necessity. In fact, if tooling is available to ensure that links are valid that's all that really matters. It is my preference to simplify links, and adding a ./ is unnecessary.

And for links that start with ~/ those should not change, but I'll verify.

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.

3 participants