New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML character entities throw "Expected valid tag name" error #296
Comments
Ok, I might have found a possible cause. After testing multiple pages with such symbols, I sometimes got the more specific error Though there might be more causes to the "offset is longer than source length" error. I also got it when writing some LaTeX on a page, e.g. Both examples seems to highlight the same issue that invalid markup isn't reported properly as error, then it progresses down the chain until it eventually ends up being served by Vite which throws the cryptic "offset is longer than source length" error. Could it be that remark fails to throw an error during parsing, or that MDsveX swallows it? |
one problem is that vite throws these usless stack traces
with vitejs/vite#4782 i get
|
digging deeper node_modules/mdsvex/dist/main.cjs.js// line 8722
if (namedEntity) {
entityCharacters = characters;
entity = namedEntity;
}
// DEBUG
console.log(`\n\nmdsvex cjs 8727: found entity in ${characters}. named ${namedEntity}. type ${type}`);
//console.dir(new Error()); // line 8815
// Found it!
// First eat the queued characters as normal text, then eat an entity.
if (reference) {
flush();
prev = now();
index = end - 1;
column += end - start + 1;
result.push(reference);
// DEBUG
console.log(`mdsvex cjs 8827: push reference ${reference}`); output
where does this code come from? lets ask github - looks like parse-entities so the problem is ... const toMDAST = unified()
.use(markdown) // HERE simple but wrong: <
<div title="<"/> would become <
<div title="&lt;"/> so either set options via |
quickfix // cjs js line 8716
if (terminated) {
end++;
namedEntity = type === name$1 ? decodeEntity_1(characters) : false;
// QUICKFIX
if (namedEntity == '<') namedEntity = '<';
if (namedEntity == '>') namedEntity = '>';
if (namedEntity) {
entityCharacters = characters;
entity = namedEntity;
} much faster than fixing all the dependencies : )
|
Late coming to this but I don't think I think there are two issues about this now, can you check to see if this issue is reporting the same problem? |
yes, its a duplicate source here Lorem ipsum < dolor sit source there A paragraph started with <h2> with my quickfix, this is correctly rendered as
|
Thank you! In v1, I have a plan to make the use of |
This issue has more information, I'll close the other. |
in the mean time, you could use patch-package to patch the dependency |
@milahu Thanks you for digging into this and also for fixing the error message in Vite! I'm thinking it may be a good idea to submit a PR upstream to EDIT: Are you sure it's |
yepp $ cd MDsveX/packages/mdsvex
$ sed -i 's/sourcemap: false/sourcemap: true/' rollup.config.js
$ npm run build
$ npm i -g source-map-cli
$ source-map resolve dist/main.cjs.js.map 8722 0
Maps to node_modules/parse-entities/index.js:254:0
if (namedEntity) {
^ thats the problem with fixing upstream: do you have so much time to waste? ; ) |
I'm not sure an upstream PR would be accepted anyway, I'm pretty sure this is by design from previous conversations I've had. I'll Patch this dependency for the short term when I find the time (if anyone wants to submit a PR, I'll happily accept it). |
Description
When using HTML character entities like
<
in a MDsveX page with SvelteKit, Vite throws anExpected valid tag name
error(Note, before Vite 2.5.4 and SvelteKit 1.0.0-next.165 the error was a cryptic
offset is longer than source length!
. Thanks to vitejs/vite#4782 this is now fixed.)Reproduction
https://github.com/vwkd/sveltekit-bugs/tree/mdsvex-character-references
npm run dev
Expected valid tag name
System Info
Additional context
Maybe related to sveltejs/svelte#6440 ?
The text was updated successfully, but these errors were encountered: