Replies: 4 comments
-
Might be possible with markdown-it plugin to rewrite |
Beta Was this translation helpful? Give feedback.
-
// vite.config
import vue from "@vitejs/plugin-vue";
import markdown from "vite-plugin-md";
export default defineConfig({
plugins: [
vue(),
markdown({
markdownItUses: [
(md) => {
const scan = (state) => {
state.tokens.forEach((tokens) => {
if (tokens.type !== "inline") {
return;
}
const inlineTokens = tokens.children;
let isRT = false;
for (let i = 0; i < inlineTokens.length; i++) {
if (isRT && inlineTokens[i].type === "link_close") {
inlineTokens[i].tag = "router-link";
isRT = false;
} else if (inlineTokens[i].type === "link_open") {
const attrs = inlineTokens[i].attrs as any;
const href = attrs?.find((v: any) => v[0] === "href");
if (href && !href[1].startsWith("http")) {
inlineTokens[i].tag = "router-link";
inlineTokens[i].attrs = [["to", href[1]]];
isRT = true;
} else {
inlineTokens[i].attrs.push(["rel", "noopener noreferrer"]);
inlineTokens[i].attrs.push(["target", "_blank"]);
}
}
}
});
}
md.core.ruler.push("router-link", scan);
},
],
}),
...
],
...
}) |
Beta Was this translation helpful? Give feedback.
-
this can be done today (as effectively built-in functionality), just use the |
Beta Was this translation helpful? Give feedback.
-
Please explain the use of link() better, because it does not seem to work anymore in the configuration
generates errors:
for "vite-plugin-md": "^0.20.0" (before upgrade it seems to work) |
Beta Was this translation helpful? Give feedback.
-
Is it possible for the plugin to treat relative links like
[link](page)
as router-links so they don't reload the page, but navigate via the vue-router?Beta Was this translation helpful? Give feedback.
All reactions