Skip to content

Commit f564456

Browse files
authored
fix: Fix markdown outputs not rendering (#147)
* fix: Fix markdown outputs not rendering Signed-off-by: Tomas Kislan <tomas@kislan.sk> * test: Add unit test for markdown output conversion in DeepnoteDataConverter Signed-off-by: Tomas Kislan <tomas@kislan.sk> --------- Signed-off-by: Tomas Kislan <tomas@kislan.sk>
1 parent 9f0d02b commit f564456

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/notebooks/deepnote/deepnoteDataConverter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ export class DeepnoteDataConverter {
236236
for (const item of output.items) {
237237
if (item.mime === 'text/plain') {
238238
data['text/plain'] = new TextDecoder().decode(item.data);
239+
} else if (item.mime === 'text/markdown') {
240+
data['text/markdown'] = new TextDecoder().decode(item.data);
239241
} else if (item.mime === 'text/html') {
240242
data['text/html'] = new TextDecoder().decode(item.data);
241243
} else if (item.mime === 'application/json') {
@@ -392,6 +394,10 @@ export class DeepnoteDataConverter {
392394
);
393395
}
394396

397+
if (data['text/markdown']) {
398+
items.push(NotebookCellOutputItem.text(data['text/markdown'] as string, 'text/markdown'));
399+
}
400+
395401
if (data['text/plain']) {
396402
let mimeType = 'text/plain';
397403
// deepnote-toolkit returns the text/plain mime type for big number outputs

src/notebooks/deepnote/deepnoteDataConverter.unit.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,46 @@ suite('DeepnoteDataConverter', () => {
473473
const outputData = JSON.parse(new TextDecoder().decode(outputs[0].items[0].data));
474474
assert.deepStrictEqual(outputData, sqlMetadata);
475475
});
476+
477+
test('converts text/markdown output', () => {
478+
const markdownContent = '## Result\n\nThis is **formatted** output.';
479+
480+
const deepnoteOutputs: DeepnoteOutput[] = [
481+
{
482+
output_type: 'execute_result',
483+
execution_count: 1,
484+
data: {
485+
'text/markdown': markdownContent,
486+
'text/plain': 'Result\n\nThis is formatted output.'
487+
}
488+
}
489+
];
490+
491+
const blocks: DeepnoteBlock[] = [
492+
{
493+
blockGroup: 'test-group',
494+
id: 'block1',
495+
type: 'code',
496+
content: 'display_markdown()',
497+
sortingKey: 'a0',
498+
outputs: deepnoteOutputs
499+
}
500+
];
501+
502+
const cells = converter.convertBlocksToCells(blocks);
503+
const outputs = cells[0].outputs!;
504+
505+
assert.strictEqual(outputs.length, 1);
506+
assert.strictEqual(outputs[0].items.length, 2);
507+
508+
const markdownItem = outputs[0].items.find((item) => item.mime === 'text/markdown');
509+
const plainItem = outputs[0].items.find((item) => item.mime === 'text/plain');
510+
511+
assert.ok(markdownItem, 'Should have text/markdown item');
512+
assert.ok(plainItem, 'Should have text/plain item');
513+
assert.strictEqual(new TextDecoder().decode(markdownItem!.data), markdownContent);
514+
assert.strictEqual(new TextDecoder().decode(plainItem!.data), 'Result\n\nThis is formatted output.');
515+
});
476516
});
477517

478518
suite('round trip conversion', () => {

0 commit comments

Comments
 (0)