From f58ed60d57020fb73534578e20ac5527e7a5ed15 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke <marijnh@gmail.com> Date: Fri, 13 Jan 2012 08:56:08 +0100 Subject: [PATCH] Allow modes to return space-separated sets with multiple styles for a token --- lib/codemirror.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/codemirror.js b/lib/codemirror.js index 62f62ce00..56e5d6721 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -2272,6 +2272,10 @@ var CodeMirror = (function() { if (sfrom == sto) sfrom = null; var len = allText.length; if (endAt != null) len = Math.min(endAt, len); + function styleToClass(style) { + if (!style) return null; + return "cm-" + style.replace(/ +/g, " cm-"); + } if (!allText && endAt == null) span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null); @@ -2280,7 +2284,7 @@ var CodeMirror = (function() { var str = st[i], style = st[i+1], l = str.length; if (ch + l > len) str = str.slice(0, len - ch); ch += l; - span(str, style && "cm-" + style); + span(str, styleToClass(style)); } else { var pos = 0, i = 0, text = "", style, sg = 0; @@ -2317,7 +2321,7 @@ var CodeMirror = (function() { span(end > upto ? text.slice(0, upto - pos) : text, appliedStyle); if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;} pos = end; - text = st[i++]; style = "cm-" + st[i++]; + text = st[i++]; style = styleToClass(st[i++]); } } if (sfrom != null && sto == null) span(" ", "CodeMirror-selected"); -- GitLab