CoffeeScript

78 views
Skip to first unread message

Ivan Sagalaev

unread,
Mar 19, 2012, 3:57:10 AM3/19/12
to highl...@googlegroups.com
There's an ongoing work on CoffeeScript support[1]. I wanted to address
a few known issues:

> ` tick around embedded javascript are included into mode, so in some
styles they are also 50% transparent

This is easily solved with excludeBegin and excludeEnd[2]. And since
CoffeeScript wants to embed JavaScript it should say `Require:
javascript.js` in the top comment, like this[3].

> functions without patrameters (like two = -> 2) is not matched

I've looked at the current function mode definition and it feels a
little bit suspicious. It doesn't seem a good idea to include param
parentheses in the the begin regexp. The submode "params" should pick it
up all by itself. This way there'd be no need in returnBegin which is
always dangerous.

Also the returnBegin in params itself looks completely unneeded.

> For Javascript/Coffeescript separation illegal "function" in default
mode may be used

This would prevent a variable named "function" which is still legal in
CoffeeScript (or is it?) Anyway it's hard to tune relevance without the
actual code snippet that is detected wrong.


[1]: https://github.com/Sannis/highlight.js/tree/dnagir-coffeescript
[2]:
http://softwaremaniacs.org/wiki/doku.php/highlight.js:mode_reference#excludebegin_excludeend
[3]:
https://github.com/isagalaev/highlight.js/blob/master/src/languages/django.js#L3

Oleg Efimov

unread,
Mar 19, 2012, 3:46:03 PM3/19/12
to highl...@googlegroups.com
Thanks for your reply!


> This is easily solved with excludeBegin and excludeEnd[2]. And since
> CoffeeScript wants to embed JavaScript it should say `Require:
> javascript.js` in the top comment, like this[3].
I've look into XML definition and there is no `Require` there, so I didn't add it.
So, I'll add `Require: css.js, javascript.js` also in xml.js.

> I've looked at the current function mode definition and it feels a
> little bit suspicious. It doesn't seem a good idea to include param
> parentheses in the the begin regexp. The submode "params" should pick it
> up all by itself. This way there'd be no need in returnBegin which is
> always dangerous.
> Also the returnBegin in params itself looks completely unneeded.
I need to try one more time, previous varians uses separate begin/end regexp without parentheses.


> This would prevent a variable named "function" which is still legal in
> CoffeeScript (or is it?) Anyway it's hard to tune relevance without the
> actual code snippet that is detected wrong.
I think it doesn't matter if function definition mode will work properly.

понедельник, 19 марта 2012 г. 11:57:10 UTC+4 пользователь Ivan Sagalaev написал:

Oleg Efimov

unread,
Mar 19, 2012, 5:59:02 PM3/19/12
to highl...@googlegroups.com
Sorry for wrong answer place.

I've finished with this issues anp push combined commit: https://github.com/Sannis/highlight.js/commit/ca289752f73964cd11b158f874505931db1bea76
There is only one ugly thing IMO: two modes for function declarations.

понедельник, 19 марта 2012 г. 11:57:10 UTC+4 пользователь Ivan Sagalaev написал:
There's an ongoing work on CoffeeScript support[1]. I wanted to address

Ivan Sagalaev

unread,
Mar 23, 2012, 9:03:41 PM3/23/12
to highl...@googlegroups.com
On 03/19/2012 02:59 PM, Oleg Efimov wrote:
> Sorry for wrong answer place.
>
> I've finished with this issues anp push combined commit:
> https://github.com/Sannis/highlight.js/commit/ca289752f73964cd11b158f874505931db1bea76
> There is only one ugly thing IMO: two modes for function declarations.

Thanks a lot, Oleg! I've merged this a couple of hours ago.

I managed to unify function definitions into one and made some more
changes[1]. Now we just need to test it thoroughly.

I also wanted to note that I was wrong about the "Requires" header. It's
not strictly required for sub-languages after all. The only place where
it is used now is django.js that actually uses `hljs.LANGUAGES.xml` in
its code and this is why it needs some way to ensure that it is
available. It might be useful for coffeescript to use some data defined
in javascript.js but apparently they don't share that much to warrant
the complication.

[1]:
https://github.com/isagalaev/highlight.js/commit/5e342d8ddfedb8a34638fe7d96eb38bf3b445c69

Ivan Sagalaev

unread,
Mar 24, 2012, 2:23:29 AM3/24/12
to highl...@googlegroups.com
On 03/23/2012 06:03 PM, Ivan Sagalaev wrote:
> Thanks a lot, Oleg! I've merged this a couple of hours ago.
>
> I managed to unify function definitions into one and made some more
> changes[1]. Now we just need to test it thoroughly.

Forgot one thing that bothered me… Right now a colon (":") is defined as
one of the delimiters between the function title and the rest of the
header so the title "cube" is highlighted in the following code:

math =
root: Math.sqrt
square: square
cube: (x) -> x * square x

This looks a bit out of place. May be it's not a good idea to highlight
inline functions within an object because it makes it inconsistent with
other keys that are not highlighted. What do you think?

Oleg Efimov

unread,
Mar 24, 2012, 10:09:25 AM3/24/12
to highl...@googlegroups.com
Thanks, I'll update my fork.
 
I managed to unify function definitions into one and made some more
changes[1]. Now we just need to test it thoroughly.
 
I've tried something like this, but doing it in wrong way. I have no contra-arguments about your mode definition.

I also wanted to note that I was wrong about the "Requires" header. It's 
not strictly required for sub-languages after all. The only place where 
it is used now is django.js that actually uses `hljs.LANGUAGES.xml` in 
its code and this is why it needs some way to ensure that it is 
available. It might be useful for coffeescript to use some data defined 
in javascript.js but apparently they don't share that much to warrant 
the complication.

Ok. I think we should add "Suggested" or "SubLanguages" field to header.
It may be used in pair with "Requires" in console build tool and on web site
if we decide to create download page there.


суббота, 24 марта 2012 г. 5:03:41 UTC+4 пользователь Ivan Sagalaev написал:

Oleg Efimov

unread,
Mar 24, 2012, 10:19:21 AM3/24/12
to highl...@googlegroups.com

Forgot one thing that bothered me… Right now a colon (":") is defined as
one of the delimiters between the function title and the rest of the
header so the title "cube" is highlighted in the following code:

     math =
       root:   Math.sqrt
       square: square
       cube:   (x) -> x * square x

This looks a bit out of place. May be it's not a good idea to highlight
inline functions within an object because it makes it inconsistent with
other keys that are not highlighted. What do you think?

I think this is more personal feeling, so you can do this as you like.
But there is similar behaviour in JavaScript, for example with such code:

var math = {
  root:   Math.sqrt,
  square: function (x) { return x*x; },
  cube:   function cube (x) { return x*x*x; }
};

Both 'function' keywords will be highlighted and 'cube' for named function will be highlighted too.
So I think this code fragment will be hightlighted similar in JavaScripot and CoffeeScript.

Ivan Sagalaev

unread,
Mar 25, 2012, 1:49:22 AM3/25/12
to highl...@googlegroups.com
On 03/24/2012 07:19 AM, Oleg Efimov wrote:
> I think this is more personal feeling, so you can do this as you like.
> But there is similar behaviour in JavaScript, for example with such code:
>
> var math = {
> root: Math.sqrt,
> square: function (x) { return x*x; },
> cube: function cube (x) { return x*x*x; }
> };
>
>
> Both 'function' keywords will be highlighted and 'cube' for named
> function will be highlighted too.
> So I think this code fragment will be hightlighted similar in
> JavaScripot and CoffeeScript.

Well, "function" is a keyword, not a title. I can't explain properly
where the difference is right now, I suppose I'm not sure myself. But it
just feels weird :-). I'll drop the colon for now and see how it goes.
It costs nothing to bring it back at any time :-).

Oleg Efimov

unread,
Mar 25, 2012, 7:21:52 AM3/25/12
to highl...@googlegroups.com
I'm agree :)
In my JavaScript example `cube` is highlighted on right side, so this
is different with my first mode for CoffeeScript.

25 марта 2012 г. 9:49 пользователь Ivan Sagalaev
<man...@softwaremaniacs.org> написал:

--
Best regards,
Oleg "Sannis" Efimov

http://sannis.ru

Jeremy Ashkenas

unread,
Mar 13, 2013, 12:49:56 AM3/13/13
to highl...@googlegroups.com
Sorry to unbury this old post ... but it looks like the current version of the CoffeeScript highlighting could use a little bit more love. Simple things like operators, function glyphs, and function parameters aren't being highlighted at all...

I'm going to switch to use Highlight.js as the default highlighter for Docco, so there's going to soon be a bunch more folks using it for this.

Cheers,
Jeremy

Ivan Sagalaev

unread,
Mar 17, 2013, 1:23:59 AM3/17/13
to highl...@googlegroups.com
> Sorry to unbury this old post ... but it looks like the current version
> of the CoffeeScript highlighting could use a little bit more love.
> Simple things like operators, function glyphs, and function parameters
> aren't being highlighted at all...
>
> I'm going to switch to use Highlight.js as the default highlighter for
> Docco, so there's going to soon be a bunch more folks using it for this.

From the comments on GitHub I understand you made the switch recently.
I hope to get the pending CoffeeScript improvements branch in shape
(mostly, wrap my own head around it) so we can improve on it further.
Reply all
Reply to author
Forward
0 new messages