MCPcopy Index your code
hub / github.com/documentcloud/visualsearch / highlight

Function highlight

docs/assets/highlight.js:160–359  ·  view source on GitHub ↗
(language_name, value)

Source from the content-addressed store, hash-verified

158 /* Core highlighting function */
159
160 function highlight(language_name, value) {
161
162 function subMode(lexem, mode) {
163 for (var i = 0; i < mode.contains.length; i++) {
164 if (mode.contains[i].beginRe.test(lexem)) {
165 return mode.contains[i];
166 }
167 }
168 }
169
170 function endOfMode(mode_index, lexem) {
171 if (modes[mode_index].end && modes[mode_index].endRe.test(lexem))
172 return 1;
173 if (modes[mode_index].endsWithParent) {
174 var level = endOfMode(mode_index - 1, lexem);
175 return level ? level + 1 : 0;
176 }
177 return 0;
178 }
179
180 function isIllegal(lexem, mode) {
181 return mode.illegalRe && mode.illegalRe.test(lexem);
182 }
183
184 function compileTerminators(mode, language) {
185 var terminators = [];
186
187 for (var i = 0; i < mode.contains.length; i++) {
188 terminators.push(mode.contains[i].begin);
189 }
190
191 var index = modes.length - 1;
192 do {
193 if (modes[index].end) {
194 terminators.push(modes[index].end);
195 }
196 index--;
197 } while (modes[index + 1].endsWithParent);
198
199 if (mode.illegal) {
200 terminators.push(mode.illegal);
201 }
202
203 return langRe(language, '(' + terminators.join('|') + ')', true);
204 }
205
206 function eatModeChunk(value, index) {
207 var mode = modes[modes.length - 1];
208 if (!mode.terminators) {
209 mode.terminators = compileTerminators(mode, language);
210 }
211 mode.terminators.lastIndex = index;
212 var match = mode.terminators.exec(value);
213 if (match)
214 return [value.substr(index, match.index - index), match[0], false];
215 else
216 return [value.substr(index), '', true];
217 }

Callers 2

processBufferFunction · 0.85
highlightBlockFunction · 0.85

Calls 3

eatModeChunkFunction · 0.85
processModeInfoFunction · 0.85
escapeFunction · 0.70

Tested by

no test coverage detected