highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.62k stars 3.58k forks source link

Convert from TextMate grammar #1513

Closed goodmind closed 5 years ago

goodmind commented 7 years ago

Is there converters from textmate grammars or I need to rewrite grammar manually?

isagalaev commented 7 years ago

No, there's no converter. Mostly due to our peculiar syntax and also different philosophies in what gets highlighted. Look at Language definition guide and Style guide.

goodmind commented 7 years ago

@isagalaev well, how to do something like beginCaptures?

isagalaev commented 7 years ago

This is something that highlight.js doesn't have, and what makes a generic converter impossible :-)

The more useful answer depends on what you're trying to achieve. Sometimes there are highlight.js-specific solutions, sometimes we just straight up don't want to highlight something. So please provide an example!

goodmind commented 7 years ago

I have this grammar and want to convert it into highlight.js one: https://github.com/goodmind/language-typelanguage/blob/master/grammars/typelanguage.tmLanguage.json

And I have combinator-declaration-without-hash with begin regex (([_$\\w]+)(\\b\\.))?([_$\\w]*)(\\b#)([[:alpha:][:alnum:]]*)\\s*

And I want to highlight captures inside it:

"2": {
    "name": "meta.definition.combinator.tl variable.other.tl"
},
"4": {
    "name": "meta.definition.combinator.tl variable.other.tl"
},
"5": {
    "name": "storage.type.tl"
},
"6": {
    "name": "storage.type.tl"
}

Example of file that I want to highlight: https://github.com/goodmind/language-typelanguage/blob/master/examples/scheme.tl

goodmind commented 7 years ago

@isagalaev any thoughts?

stevepeak commented 6 years ago

@goodmind did you end up solving this problem? I have the same one.

goodmind commented 6 years ago

@stevepeak I didn't

stevepeak commented 6 years ago

@goodmind Would you be interested in helping contribute to an open source package that does this?

goodmind commented 6 years ago

@stevepeak yes, but I think it's impossible because TextMate uses oniguruma regexp engine (doesn't work in browser at least now)

stevepeak commented 6 years ago

Oh... good to know. I'll ping you when we look more into this.

joshgoebel commented 5 years ago

If you all made any progress with a general purpose converted I'd be curious.

joshgoebel commented 5 years ago

Closing as this is asked and answered. Still if you make any progress I'd love to hear about it. :)