vscode-mdx icon indicating copy to clipboard operation
vscode-mdx copied to clipboard

Inline JSX elements (CamelCase) do not seem syntax highlighted

Open balupton opened this issue 5 years ago • 17 comments

They are treated just like markdown. Lowercasing the jsx element works for syntax highlighting, but then it doesn't function.

balupton avatar Jan 28 '19 07:01 balupton

Could you share a code snippet and/or screenshot? I don't understand what isn't syntax highlighted.

silvenon avatar Jan 28 '19 23:01 silvenon

Ah, I think you're referring to inline JSX, correct?

silvenon avatar Jan 28 '19 23:01 silvenon

Correct. Sorry, posted the issue on my phone. An example is a JSX element (so CamelCase) within a nested markdown list

balupton avatar Jan 29 '19 00:01 balupton

screen shot 2019-01-29 at 4 31 32 pm screen shot 2019-01-29 at 4 31 56 pm

balupton avatar Jan 29 '19 05:01 balupton

Yeah, in MDX that's what's classified as inline JSX, where a single line needs to be partially interpreted as Markdown and partially as JSX.

I'll see what I can do, thanks for reporting. 🙂

silvenon avatar Jan 29 '19 10:01 silvenon

Hi, any ideas how to fix this?

This is how it shows for me:

inline-tags

blummis avatar Jul 13 '19 12:07 blummis

In the near future no, I'm sorry, I'm very inexperienced with grammars in general. I think I need to rebuild this extension entirely to gain more more power over these cases because it's currently only looking for empty lines, as far as I can remember, but MDX is more complex now, with inline JSX, interpolations etc.

silvenon avatar Jul 15 '19 08:07 silvenon

Because HTML tags are also valid when written uppercase, and web components would be classified as "Unknown", maybe this can be fixed in the base text.html.markdown grammar, which also has this issue:

Screen Shot 2019-08-14 at 15 57 10

Compare that with the HTML grammar highlighting:

Screen Shot 2019-08-14 at 16 02 35

I am also not experienced with grammars, but from a cursory look it seems like you're using here:

https://github.com/silvenon/vscode-mdx/blob/fefe05634acc491a0b7c158840d7bb409a5d9605/syntaxes/mdx.tmLanguage.json#L41-L46

I will open an issue on the grammar to request feedback on this change.

karlhorky avatar Aug 14 '19 14:08 karlhorky

Opened https://github.com/microsoft/vscode/issues/79119 for this.

Edit: Copied to microsoft/vscode-markdown-tm-grammar#49, in case that is the correct place for it.

karlhorky avatar Aug 14 '19 14:08 karlhorky

Caveat: JSX highlighting would be of course better if someone can crack it (cc @mjbvz, could you possibly point us in the right direction for updating the grammar?) - because it would show a different color for capitalized tags, but this would at least be an improvement on the current situation.

karlhorky avatar Aug 14 '19 14:08 karlhorky

Well case insensitivity was added in https://github.com/microsoft/vscode-markdown-tm-grammar/commit/67b9b347e34950f3e63ec923e20ac620ffa2ddd7 - should be out in the next VS Code Insiders build.

But unknown / custom elements were not addressed. I've asked about that in https://github.com/microsoft/vscode-markdown-tm-grammar/issues/49#issuecomment-521658427

karlhorky avatar Aug 15 '19 14:08 karlhorky

Unknown / custom elements merged in! https://github.com/microsoft/vscode-markdown-tm-grammar/pull/54

Still is not a complete fix, because other JSX syntax like non-string props passing (<Grid style={{ background: "green" }}>) is still not highlighted, but it's a start for simple components!

karlhorky avatar Aug 20 '19 05:08 karlhorky

Great! I'll see what I can do about that. 👍 Thanks for keeping this issue updated!

silvenon avatar Aug 20 '19 10:08 silvenon

No problem :) yeah I think the "correct" way to fix it would be for inline tags (probably all inline tags) to start triggering the JSX grammar again. Not entirely sure how to do this off the top of my head, but I guess the vscode-markdown-tm-grammar code could be illuminating in this regard... They switch to the other html grammar a lot within it.

karlhorky avatar Aug 20 '19 11:08 karlhorky

Seems like looking at the Markdown grammar will be helpful in other ways too. For example, currently in the MDX grammar, the Markdown inside the HTML element is not highlighted (Markdown can be embedded within HTML if it starts at the start of the line):

Screen Shot 2019-08-28 at 12 20 38

Compare that to the Markdown grammar:

Screen Shot 2019-08-28 at 12 20 28

karlhorky avatar Aug 28 '19 10:08 karlhorky

The fix I refer to in https://github.com/silvenon/vscode-mdx/issues/9#issuecomment-522855414 above was released in VS Code 1.38 btw:

https://code.visualstudio.com/updates/v1_38#_notable-fixes

79478: Highlight custom html tags in markdown files

karlhorky avatar Sep 12 '19 19:09 karlhorky

This was fixed in the VSCode Markdown lib but still broken in this one.

felixakiragreen avatar Apr 14 '21 17:04 felixakiragreen