Skip to content

Commit afd07cd

Browse files
authored
Improve syntax highlighting, fix #14 By yuezk
Improve syntax highlighting, fix #14
2 parents 202ee18 + 8b15f7f commit afd07cd

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

after/syntax/javascript.vim

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,39 @@ if exists('s:current_syntax')
2121
let b:current_syntax = s:current_syntax
2222
endif
2323

24-
" <tag></tag>
25-
" s~~~~~~~~~~~e
24+
" <tag id="sample">
25+
" s~~~~~~~~~~~~~~~e
26+
" and self close tag
27+
" <tag id="sample" />
28+
" s~~~~~~~~~~~~~~~~~e
29+
syntax region jsxTag
30+
\ start=+<\([^ /!?<>="':]\+\)\@=+
31+
\ skip=+</[^ /!?<>"']\+>+
32+
\ end=+/\@<!>+
33+
\ end=+\(/>\)\@=+
34+
\ contained
35+
\ contains=jsxTag,jsxError,jsxTagName,jsxAttrib,jsxEqual,jsxString,jsxEscapeJs,
36+
\jsxCloseString
37+
\ keepend
38+
\ extend
39+
40+
41+
" <tag></tag>
42+
" s~~~~~~~~~e
43+
" and self close tag
44+
" <tag/>
45+
" s~~~~e
2646
syntax region jsxRegion
2747
\ start=+<\z([^ /!?<>="':]\+\)+
2848
\ skip=+<!--\_.\{-}-->+
29-
\ end=+</\z1\_\s\{-}[^(=>)]>+
30-
\ end=+>\n\?\s*)\@=+
31-
\ end=+>\n\?\s*}\@=+
32-
\ end=+>;\@=+
33-
\ end=+\n\?\s\*,+
34-
\ end=+\s*>,\@=+
35-
\ end=+\s\+:\@=+
49+
\ end=+</\z1>+
50+
\ end=+/>+
3651
\ fold
37-
\ contains=jsxCloseString,jsxCloseTag,jsxTag,jsxComment,jsFuncBlock,
52+
\ contains=jsxRegion,jsxCloseString,jsxCloseTag,jsxTag,jsxComment,jsFuncBlock,
3853
\@Spell
3954
\ keepend
4055
\ extend
4156

42-
" <tag id="sample">
43-
" s~~~~~~~~~~~~~~~e
44-
syntax region jsxTag
45-
\ start=+<[^ /!?<>"':]\@=+
46-
\ end=+>+
47-
\ matchgroup=jsxCloseTag end=+/>+
48-
\ contained
49-
\ contains=jsxError,jsxTagName,jsxAttrib,jsxEqual,jsxString,jsxEscapeJs,
50-
\jsxCloseString
51-
5257
" </tag>
5358
" ~~~~~~
5459
syntax match jsxCloseTag

sample.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
class App extends Component {
2+
render() {
3+
// NOTCE: no `;` after.
4+
const arr = <div></div>
5+
6+
// Codes highlight incorrectly
7+
var foo = 'foo';
8+
if (foo === 'foo') {
9+
console.log('hello');
10+
}
11+
12+
var el = a < 0
13+
? <div></div>
14+
: <a></a>
15+
16+
var b = el || <div>hello, world</div>
17+
}
18+
}
19+
120
class Hoge extends React.Component {
221
constructor(props) {
322
super(props);

0 commit comments

Comments
 (0)