Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 5e1ca4f

Browse files
committed
[css mode] Make @import highlighting consistent with other contexts
Closes #3475
1 parent e359853 commit 5e1ca4f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

mode/css/css.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
164164
return popContext(state);
165165
} else if (supportsAtComponent && /@component/.test(type)) {
166166
return pushContext(state, stream, "atComponentBlock");
167-
} else if (/@(media|supports|(-moz-)?document)/.test(type)) {
167+
} else if (/^@(-moz-)?document$/.test(type)) {
168+
return pushContext(state, stream, "documentTypes");
169+
} else if (/^@(media|supports|(-moz-)?document|import)$/.test(type)) {
168170
return pushContext(state, stream, "atBlock");
169-
} else if (/@(font-face|counter-style)/.test(type)) {
171+
} else if (/^@(font-face|counter-style)/.test(type)) {
170172
state.stateArg = type;
171173
return "restricted_atBlock_before";
172174
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
@@ -259,17 +261,24 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
259261
return pass(type, stream, state);
260262
};
261263

264+
states.documentTypes = function(type, stream, state) {
265+
if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
266+
override = "tag";
267+
return state.context.type;
268+
} else {
269+
return states.atBlock(type, stream, state);
270+
}
271+
};
272+
262273
states.atBlock = function(type, stream, state) {
263274
if (type == "(") return pushContext(state, stream, "atBlock_parens");
264-
if (type == "}") return popAndPass(type, stream, state);
275+
if (type == "}" || type == ";") return popAndPass(type, stream, state);
265276
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
266277

267278
if (type == "word") {
268279
var word = stream.current().toLowerCase();
269280
if (word == "only" || word == "not" || word == "and" || word == "or")
270281
override = "keyword";
271-
else if (documentTypes.hasOwnProperty(word))
272-
override = "tag";
273282
else if (mediaTypes.hasOwnProperty(word))
274283
override = "attribute";
275284
else if (mediaFeatures.hasOwnProperty(word))

mode/css/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"}");
121121

122122
MT("empty_url",
123-
"[def @import] [tag url]() [tag screen];");
123+
"[def @import] [atom url]() [attribute screen];");
124124

125125
MT("parens",
126126
"[qualifier .foo] {",

0 commit comments

Comments
 (0)