-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make ERB, Handlebars, PHP and Smarty highlight properly in NodeJS #1367
Conversation
Is |
I guess it could, at least for ERB, Handlebars and Smarty (PHP is slightly different). But where would we put it? I'm not really in favor of adding it directly to |
Testing this on https://codepen.io/anon/pen/dmzpKg it dosen't seem to work. |
I was thinking the |
Ruby needs to be included before ERB. See https://codepen.io/anon/pen/eMEgNo
I think this is too much code, used by too few languages (3 or 4 out of 141), to belong in |
Possibly-terrible-idea: Have all of them depend on a "language" who's sole responsibility is to make this function available on |
Maybe this can be something like I'll give it a try this weekend, we'll see how this goes. (On a side note, Twig and Django components should probably be rewritten in the same fashion, since they belong to the same kind of languages. Although it can be done at anytime later) |
3dcb413
to
0a468ef
Compare
Ok, so I gave this a try and it works really well. I managed to make all four of the languages behave the same way. Their definition does not extend Markup anymore. Instead, like PHP does, they switch the grammar to Markup in Sorry the diff is getting a bit hard to read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach, this makes the language implementations a lot cleaner.
Since ERB, Handlebars, PHP and Smarty currently rely on
before-highlight
andafter-highlight
hooks to be highlighted properly, they can't be easily highlighted using directly thePrism.highlight()
function.#1357 added the
after-tokenize
hook to post-process tokens directly in thePrism.highlight()
function. This PR adds abefore-tokenize
hook, and essentially translates what we were previously doing with string replacement, but using the array of tokens.This should remove the need for the
backupCode
/before-insert
hack, since the code is properly tokenized at the end of thehighlight()
function.I also converted the tests from
.js
format to.test
format, since the test runner can now run them normally.