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

JavaScript highlighting should be improved #963

Closed
felixsanz opened this issue Jun 1, 2016 · 12 comments
Closed

JavaScript highlighting should be improved #963

felixsanz opened this issue Jun 1, 2016 · 12 comments

Comments

@felixsanz
Copy link

JS highlighting fails too much, even at simple use cases. Example:

Examle

Most of it it's wrong. I wish i could provide a patch but i can just report it.

@Golmote
Copy link
Contributor

Golmote commented Jun 1, 2016

Please provide the entirety of the code you're trying to highlight. It seems to me that the initial highlighting problem occurs before this snippet.

@felixsanz
Copy link
Author

felixsanz commented Jun 1, 2016

You're right. That single piece works better as standalone.

import cluster from 'cluster'
import os from 'os'

const workers = os.cpus().length

cluster.setupMaster({ exec: 'app.js' })

function log(msg) {
  console.log(`[SERVER] ${new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')} ${msg}`)
}

log(`Master with pid ${process.pid} starting...`)

for (let i = 0; i < workers; i++) {
  cluster.fork()
}

cluster.on('exit', (worker, code, signal) => {
  log(`worker with pid ${worker.process.pid} died. Restarting...`)
  cluster.fork()
})

cluster.on('online', worker => {
  log(`Worker with pid ${worker.process.pid} started`)
})

^ GitHub's syntax highlighter has no problems

@Golmote
Copy link
Contributor

Golmote commented Jun 1, 2016

@LeaVerou @zeitgeist87 Does it look safe to you to move up the template string pattern in the language definition of JS so that it's processed before normal strings? IMO it is much more common to encounter quotes inside template strings than backticks inside normal strings. What do you think?

@LeaVerou
Copy link
Member

LeaVerou commented Jun 1, 2016

Agreed.

@zeitgeist87
Copy link
Collaborator

If we move the template-string before string, then one of the tests for coffeescript fails, because coffeescript uses backticks for inline javascript. However this is easily fixed by adding the following line to the coffeescript language:

delete Prism.languages.coffeescript['template-string'];

Shall I commit my changes?

@LeaVerou
Copy link
Member

LeaVerou commented Jun 3, 2016

Sounds good to me!

@Golmote
Copy link
Contributor

Golmote commented Jun 3, 2016

Yup, agreed!

zeitgeist87 added a commit that referenced this issue Jun 3, 2016
It is more likely that single and double quotes appear in
a template string, than backticks in a normal string. Fixes issue
#963.
@zeitgeist87
Copy link
Collaborator

Should be fixed with [1158e46]

@felixsanz
Copy link
Author

I was about to test this (even if it's already a closed issue...) to report the status and how that code renders now, but i don't know how to install this with npm since this versions are published into gh-pages branch (uh?), and that is not released into npm, right?

How i do install it then?

@zeitgeist87
Copy link
Collaborator

For a quick test you can use http://prismjs.com/test.html or check out the gh-pages branch manually. The fix will be published to npm with the next release, which should be soon.

@felixsanz
Copy link
Author

this look much better now, thanks

@exander77
Copy link

exander77 commented May 13, 2017

It still seems to be broken for backticks, try this:

var a = [
    '`a',
    '`b'
];

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

No branches or pull requests

5 participants