Skip to content
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

TypeScript: Not highlighting custom class / interface types #1401

Open
JaimeStill opened this issue Apr 20, 2018 · 5 comments
Open

TypeScript: Not highlighting custom class / interface types #1401

JaimeStill opened this issue Apr 20, 2018 · 5 comments

Comments

@JaimeStill
Copy link

JaimeStill commented Apr 20, 2018

Using: prismjs@1.14.0

Does not continue to highlight custom class / interface types after they are initially defined.

Example, BigData is not highlighted:

image

Also, a StackBlitz.

@JaimeStill JaimeStill changed the title TypeScript: Not highlighting generic class / interface types TypeScript: Not highlighting custom class / interface types Apr 20, 2018
@Golmote
Copy link
Contributor

Golmote commented Apr 22, 2018

Hi! Thanks for reporting.
Unfortunately, Prism is not a parser and it has no knowledge regarding the actual meaning of your code. This means it can't recognize whether BigData is a class or anything else when used outside of a few easily identifiable places.

More specifically, in your example, the first occurrence of BigData can easily be matched as a class (or rather an interface in that case) because it immediately follows the interface keyword. But Prism has no easy way to identify it later.

The only thing I can think of would be to use the after-tokenize hook to post-process the tokens and identify classes used elsewhere. That would require some work, but I think it's doable. (See related #1228 (comment))

I don't think this is something we want to handle by default in Prism.

@JaimeStill
Copy link
Author

Hi! Thank you for your response and the corresponding information. I'll check it out and see what I can do with it.

I believe, in the cases shown above, that there are a couple standard instances with TypeScript where you can always easily match a custom class name:

  1. As a type constraint inside of generic angle brackets

  2. Inside of parenthesis following a colon.

@001AJD
Copy link

001AJD commented Jul 9, 2020

I am trying to highlight this piece of code but prismjs is not highlighting the type of object

products: Observable<Product[]>;

Prismjs should have highlighted <Products[]> but instead prismjs omitted it, this is what I got as output

image

Any solutions to this?

@RunDevelopment
Copy link
Member

@001AJD You have to escape all < in the markup of the <code> element with &lt;.
The browser will interpret <Products[]> as a valid HTML tag. Prism only highlights the text content of <code> elements meaning that it will ignore all HTML tags in <code> elements. You can work around this with Unescaped Markup though (or by simply escaping all < characters).

@001AJD
Copy link

001AJD commented Jul 13, 2020

@001AJD You have to escape all < in the markup of the <code> element with &lt;.
The browser will interpret <Products[]> as a valid HTML tag. Prism only highlights the text content of <code> elements meaning that it will ignore all HTML tags in <code> elements. You can work around this with Unescaped Markup though (or by simply escaping all < characters).

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants