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

added JSX tags highlighting #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js.nanorc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ color yellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\
color yellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
color yellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"

## JSX tags
color cyan "<[^> ]+"
color cyan "<[a-zA-Z][a-zA-Z0-9]*>"
Copy link
Contributor

@Piterden Piterden Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe list HTML tags here? To differentiate a color of standard tags from components?

Also <[a-zA-Z][a-zA-Z0-9]*> will match <>, but <[a-zA-Z][a-zA-Z0-9]+> don't!

Copy link
Contributor Author

@remyoudemans remyoudemans Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a different color for standard tags rather than components could be nice, but don't you think listing them is overkill? I would suggest it's sufficient to say that <[a-z]+> is an HTML tag and <[A-Z][a-zA-Z0-9]*> is a component.

(Also <[a-zA-Z][a-zA-Z0-9]*> will not match <>, it will match at least <[a-zA-Z]>.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what if someone uses all caps when they do their HTML??

<HTML>
<BODY>
I LIKE SCREAMING CAPS!!!
</BODY>
</HTML>

dumb i agree, but I've seen this in more than one place...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About */+ you are right, it's my bad, sorry))

About overkill: listing of JS reserved words is not overkill...

HTML has 144 tags. Reference https://developer.mozilla.org/en-US/docs/Web/HTML/Element

document.body.innerText.match(/<\w+>/g).reduce((acc, cur) => {
  if (!acc.includes(cur)) {
    acc.push(cur)
  }
  return acc
}, [])

Run this code in the console on a reference page.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JSX, any tag that starts with a lowercase letter is assumed to be a native tag, whereas tags starting with uppercase letters are component tags.

color cyan "</[a-zA-Z][a-zA-Z0-9]*>"
color cyan ">$"
color cyan "/>"

## Keywords
color green "\<(abstract|await|boolean|break|byte|case|catch|char)\>"
color green "\<(class|const|continue|debugger|default|delete|double)\>"
Expand Down