This repository was archived by the owner on Feb 4, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
src/main/java/org/scijava/jupyter/kernel/evaluator Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ private void addLanguage(String languageName) {
132132 String firstLanguage = this .scriptEngines .keySet ().iterator ().next ();
133133 bindings = this .scriptEngines .get (firstLanguage ).getBindings (ScriptContext .ENGINE_SCOPE );
134134 }
135-
135+
136136 log .info ("Script Language for '" + languageName + "' found." );
137137 ScriptLanguage scriptLanguage = scriptService .getLanguageByName (languageName );
138138 this .scriptLanguages .put (languageName , scriptLanguage );
@@ -154,10 +154,20 @@ private void addLanguage(String languageName) {
154154 private String setLanguage (String code ) {
155155
156156 if (code .startsWith ("#!" )) {
157- this .languageName = code .substring (2 , code .indexOf ("\n " )).trim ();
158157
159- // Return the code string without the first line
160- code = code .substring (code .indexOf (System .getProperty ("line.separator" )) + 1 );
158+ // If code is composed of multiple lines
159+ if (code .split ("\n " ).length > 1 ) {
160+ this .languageName = code .substring (2 , code .indexOf ("\n " )).trim ();
161+
162+ // Return the code string without the first line
163+ code = code .substring (code .indexOf (System .getProperty ("line.separator" )) + 1 );
164+ } // If only one line
165+ else {
166+ this .languageName = code .substring (2 ).trim ();
167+
168+ code = "" ;
169+ }
170+
161171 }
162172
163173 this .addLanguage (this .languageName );
You can’t perform that action at this time.
0 commit comments