Bug 325805 - js.xml: Syntax highlighting for js does not understand shebang
Summary: js.xml: Syntax highlighting for js does not understand shebang
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Unclassified
Component: syntax (show other bugs)
Version: 3.10.5
Platform: Kubuntu Packages Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-09 11:13 UTC by Magnus Hoff
Modified: 2014-04-29 10:08 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Screenshot of problem in action (31.86 KB, image/png)
2013-10-09 11:32 UTC, Magnus Hoff
Details
Patch that fixes the problem (1.02 KB, patch)
2013-10-11 22:00 UTC, Magnus Hoff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Hoff 2013-10-09 11:13:15 UTC
When writing node.js scripts it is common to include a shebang at the top, like `#!/usr/bin/env node`, and save it in a .js-file. However, the syntax highlighter for JavaScript does not understand the shebang, and tries to highlight it as JavaScript.

It is understood as two literal regular expressions (/usr/bin and /env node), the last of which is not closed, meaning that the rest of the file is attempted understood as part of the last regular expression.

This defeats syntax highlighting for .js-files that start with a shebang.
Comment 1 Magnus Hoff 2013-10-09 11:32:43 UTC
Created attachment 82742 [details]
Screenshot of problem in action
Comment 2 Dominik Haumann 2013-10-09 13:26:03 UTC
Can you look into prolog.xml and look how it's done there, and then modify javascript.xml accordingly and provide a patch?
Comment 3 Magnus Hoff 2013-10-09 13:36:08 UTC
If I can find the time for it, I will certainly post a patch here :)
Comment 4 Magnus Hoff 2013-10-11 22:00:31 UTC
Created attachment 82793 [details]
Patch that fixes the problem

This fixes the bug on my system. I have not checked out source code to produce this, I simply made a best effort based on the files on my system. It does, however, work for me :)
Comment 5 Magnus Hoff 2014-04-14 20:52:58 UTC
Submitted to reviewboard: https://git.reviewboard.kde.org/r/117571/
Comment 6 Milian Wolff 2014-04-22 21:25:54 UTC
Git commit 839ba534f61cb5713fcd2074982649ba8f950c1b by Milian Wolff, on behalf of Magnus Hoff.
Committed on 22/04/2014 at 21:24.
Pushed by mwolff into branch 'master'.

For syntax highlighting, allow .js-files to start with a shebang.

When writing node.js scripts it is common to include a shebang at the
top, like `#!/usr/bin/env node`, and save it in a .js-file. However,
the syntax highlighter for JavaScript does not understand the shebang,
and tries to highlight it as JavaScript.

It is understood as two literal regular expressions (/usr/bin and /env
node), the last of which is not closed, meaning that the rest of the
file is attempted understood as part of the last regular expression.

This defeats syntax highlighting for .js-files that start with a
shebang.

This patch allows .js files to start with a shebang.
REVIEW: 117571

M  +1    -1    part/syntax/data/coffee.xml
M  +1    -1    part/syntax/data/djangotemplate.xml
M  +1    -1    part/syntax/data/html.xml
M  +11   -0    part/syntax/data/javascript.xml
M  +2    -2    part/syntax/data/mako.xml
M  +2    -2    part/syntax/data/mediawiki.xml
M  +2    -2    part/syntax/data/php.xml
M  +1    -1    part/syntax/data/qml.xml
M  +1    -1    part/syntax/data/rhtml.xml

http://commits.kde.org/kate/839ba534f61cb5713fcd2074982649ba8f950c1b
Comment 7 Dominik Haumann 2014-04-29 10:08:26 UTC
Git commit 18a961d07f91556ef27939646599db8d228ce547 by Dominik Haumann.
Committed on 29/04/2014 at 10:08.
Pushed by dhaumann into branch 'master'.

For syntax highlighting, allow .js-files to start with a shebang

When writing node.js scripts it is common to include a shebang at the
top, like `#!/usr/bin/env node`, and save it in a .js-file. However,
the syntax highlighter for JavaScript does not understand the shebang,
and tries to highlight it as JavaScript.

It is understood as two literal regular expressions (/usr/bin and /env
node), the last of which is not closed, meaning that the rest of the
file is attempted understood as part of the last regular expression.

This defeats syntax highlighting for .js-files that start with a
shebang.

This patch allows .js files to start with a shebang.

M  +2    -2    src/syntax/data/coffee.xml
M  +2    -2    src/syntax/data/djangotemplate.xml
M  +2    -2    src/syntax/data/html.xml
M  +12   -1    src/syntax/data/javascript.xml
M  +3    -3    src/syntax/data/mako.xml
M  +3    -3    src/syntax/data/mediawiki.xml
M  +3    -3    src/syntax/data/php.xml
M  +3    -3    src/syntax/data/qml.xml
M  +2    -2    src/syntax/data/rhtml.xml

http://commits.kde.org/ktexteditor/18a961d07f91556ef27939646599db8d228ce547