Skip to content

Commit

Permalink
#5742 highlight Spark and classpath magics
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz Jurowicz committed Jul 6, 2018
1 parent 7390db3 commit cca204f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions js/notebook/src/extension/codeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const lineMagicOverlay = {
if (!state.firstMatched) {
state.firstMatched = true;

if (stream.match("%", false)) {
if (stream.match(/^%(%classpath|%spark|\w+)/)) {
state.inMagicLine = true;
}
}
Expand All @@ -94,22 +94,18 @@ const lineMagicOverlay = {

export function autoHighlightLineMagics(code_mirror) {
const current_mode = code_mirror.getOption('mode');
const first_line = code_mirror.getLine(0);
const re = /^%\w+/;

if (current_mode === LINE_MAGIC_MODE) {
return;
}

if (first_line.match(re) !== null) {
// Add an overlay mode to recognize the first line as "line magic" instead
// of the mode used for the rest of the cell.
CodeMirror.defineMode(LINE_MAGIC_MODE, (config) => {
return CodeMirror.overlayMode(CodeMirror.getMode(config, current_mode), lineMagicOverlay);
});
// Add an overlay mode to recognize the first line as "line magic" instead
// of the mode used for the rest of the cell.
CodeMirror.defineMode(LINE_MAGIC_MODE, (config) => {
return CodeMirror.overlayMode(CodeMirror.getMode(config, current_mode), lineMagicOverlay);
});

code_mirror.setOption('mode', LINE_MAGIC_MODE);
}
code_mirror.setOption('mode', LINE_MAGIC_MODE);
}

export function addLineMagicsOverlay(code_mirror) {
Expand Down

0 comments on commit cca204f

Please sign in to comment.