Skip to content

Conversation

@f3ve
Copy link

@f3ve f3ve commented Feb 3, 2024

Description

Adds an option to convert internal links to RouterLinks. Supports custom router link components. I've also added a new test suite called routerLink.test.ts. It contains a total of 4 tests.

Linked Issues

fix #37

Additional context

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.


const scriptSetupRE = /<\s*script([^>]*)\bsetup\b([^>]*)>([\s\S]*)<\/script>/mg
const defineExposeRE = /defineExpose\s*\(/mg
const internalLinkRE = /\[(.+)\]\((\/[?=\w\/-]*)\)/g
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried that this regex can lead to some false passive. Could we do it with a markdown it plugin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Any you recommend? If not, I'll look around for a plugin.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about this regex. It captured images ![my-image](/examaple) and it isn't correctly capturing links that are in the same line. I will flesh it out some more and push to this PR. Haven't found an obvious plugin to use just yet.

Copy link
Collaborator

@meteorlxy meteorlxy Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f3ve

See the links plugin in VuePress: https://github.com/vuepress/core/blob/main/packages/markdown/src/plugins/linksPlugin/linksPlugin.ts

Notice that VitePress does not use vue-router at all, so it does not have RouterLink transformation. Just put its plugin here as a reference: https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/link.ts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a common feature. Both vuepress and vitepress have lots of different customizations in their links plugin.

If it could be extract to a more customizable markdown-it plugin, maybe we can add it to https://github.com/mdit-vue/mdit-vue

Copy link
Author

@f3ve f3ve Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see! I misunderstood what antfu meant by we could do it in a plugin. This makes sense and thanks for the references! I'll look into developing this into a markdown-it plugin instead. Thanks so much for both of your time.

@f3ve
Copy link
Author

f3ve commented Feb 4, 2024

Closing this PR and will look into making this into Markdown-it plugin instead. Thanks @antfu and @meteorlxy for the advice and your time!

@f3ve f3ve closed this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants