Skip to content

Commit 014761c

Browse files
author
Prabhakar Kumar
committed
Updates indentation rules for variable outputs.
1 parent 7f9914b commit 014761c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/jupyter_matlab_kernel/matlab/+jupyter/execute.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
case 'variable'
111111
result{ii} = processVariable(outputData);
112112
case 'variableString'
113-
result{ii} = processVariable(outputData);
113+
result{ii} = processVariableString(outputData);
114114
case 'symbolic'
115115
result{ii} = processSymbolic(outputData);
116116
case 'error'
@@ -165,9 +165,27 @@
165165
result = processText(text);
166166

167167
function result = processVariable(output)
168-
text = sprintf("%s = %s\n %s", output.name, output.header, strtrim(output.value));
168+
if isempty(output.header)
169+
indentation = '';
170+
else
171+
indentation = sprintf('\n ');
172+
end
173+
text = sprintf("%s = %s%s%s", output.name, output.header, indentation, output.value);
169174
result = processText(text);
170175

176+
function result = processVariableString(output)
177+
indentation = '';
178+
useSingleLineDisplay = ~contains(output.value, sprintf(newline));
179+
if useSingleLineDisplay
180+
if ~isempty(output.header)
181+
indentation = sprintf(newline);
182+
end
183+
else
184+
indentation = sprintf(newline);
185+
end
186+
text = sprintf("%s = %s%s%s", output.name, output.header, indentation, output.value);
187+
result = processText(text);
188+
171189
% Helper function for post-processing symbolic outputs. The captured output
172190
% contains MathML representation of symbolic expressions. Since Jupyter and
173191
% GitHub have native support for LaTeX, we use EquationRenderer JS API to

tests/integration/test_matlab_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MATLABKernelTests(jupyter_kernel_test.KernelTests):
3030
code_hello_world = "disp('hello, world')"
3131

3232
# Executes code and validates output
33-
code_execute_result = [{"code": "a = 1;a = a + 1", "result": "a = \n 2"}]
33+
code_execute_result = [{"code": "a = 1;a = a + 1", "result": "a = 2"}]
3434

3535
# Clears the cell output area
3636
code_clear_output = "clc"

0 commit comments

Comments
 (0)