question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Expected valid tag name" when using special characters like <

See original GitHub issue

Hello @pngwn, thank you for this great project!

I am having an issue when using the < character inside a Markdown file. Even when replacing it with &lt;. It seems the &lt; gets replaced by < again resulting in the same error from the svelte compiler (“Expected valid tag name”). I even tried to escape the character with \ without success.

Is there any way to escape special characters so the svelte compiler does not throw an error?

My current “solution” is to wrap < inside an inline code block but I do not want to show that part as code. This is the Markdown file I am talking about: https://github.com/nymea/nymea-plugins/blob/rework-readmes/awattar/README.md This is the version with the “fixed” inline code blocks. When removing those, the error gets thrown.

I am not sure if this is a bug or if I miss something here. Just found this code section in MDSveX:

// in code nodes replace the character witrh the html entities
// maybe I'll need more of these

const entites = [
	[/</g, '&lt;'],
	[/>/g, '&gt;'],
	[/{/g, '&#123;'],
	[/}/g, '&#125;'],
];

So I guess the < character should only be replaced inside code blocks as mentioned in the comment, but using &lt; leads to the same error because somewhere during the preprocess it gets replaced with < again.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
josephgcommented, May 26, 2021

I wonder if mdsvex should interpret < and { characters followed by a space literally, generally well-formatted HTML/svelte doesn’t do this and handling this in a special way would allow a number of obvious cases to work, such as this one: #113 (comment) (tl;dr: writing foo < bar to make some didactic point)

The commonmark specification has a list of rules for what constitutes legal tags. Anything that isn’t a valid tag is escaped. This example shows a < followed by a space is not considered a valid tag name. Eg, < a> encodes to &lt; a&gt;. (As it does in this comment.)

Commonmark has a test suite of JSON content. We should get that test suite passing in mdsevx.

2reactions
josephgcommented, May 25, 2021

Its awful but double escaping seems to work:

5 &amp;lt; 10

It doesn’t work in the playground though. For some reason &amp; makes the playground hit another bug and error with Document is not defined

Read more comments on GitHub >

github_iconTop Results From Across the Web

What names are valid git tags? - Stack Overflow
You can check if the name is valid with git check-ref-format. This page contains the constraints on a valid name. Quoted from the...
Read more >
strip_tags - Manual - PHP
This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given string . It uses...
Read more >
Grammar and types - JavaScript - MDN Web Docs - Mozilla
You can also use the Unicode escape sequences as characters in identifiers. Some examples of legal names are Number_hits , temp99 , $credit ......
Read more >
docker tag
A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may...
Read more >
ExifTool FAQ
Valid characters in tag names are A-Z , a-z , 0-9 , _ and - . See the tag name documentation for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found