Open JasherIO opened 2 years ago
I was wrong about the workaround. It does remove the error in SvelteKit, but that is because the rehype plugin runs before mdsvex decodes %7B
. So, whatever is causing it is after remark/rehype in the pipeline.
// mdsvex.config.js
import { defineMDSveXConfig as defineConfig } from 'mdsvex';
import rehype_urls from 'rehype-urls';
function encode(url) {
const encoded = encodeURI(url.href);
if (url.host === 'smash.gg') {
console.log(`url.href: ${url.href}`);
console.log(`encoded: ${encoded}`);
}
return encoded;
};
const config = defineConfig({
extensions: ['.svelte.md', '.md', '.svx'],
layout: 'path_to_layout'
smartypants: {
dashes: 'oldschool'
},
remarkPlugins: [],
rehypePlugins: [ [rehype_urls, encode] ]
});
export default config;
url.href: https://smash.gg/league/rlcs-season-6/schedule?filter=%7B%22upcoming%22%3Atrue%7D
encoded: https://smash.gg/league/rlcs-season-6/schedule?filter=%257B%2522upcoming%2522%253Atrue%257D
I was pretty certain that decoding was done right at the beginning of the parse process, before anything else actually happens but I could be wrong. Will look into this when I can.
Issue
%7B
is decoded by mdsvex in anchor hrefs, thenvite-plugin-svelte
errors out on build with "Unexpected token" (I did not see an error withnpm run dev
)Reproducing
Workaround