diff --git a/src/extension/notebook.ts b/src/extension/notebook.ts index f1918d9f4..02371d1f2 100644 --- a/src/extension/notebook.ts +++ b/src/extension/notebook.ts @@ -8,6 +8,7 @@ import type { ParsedDocument } from '../types' import executor from './executors' import Languages from './languages' import { PLATFORM_OS } from './constants' +import { normalizeLanguage } from './utils' declare var globalThis: any @@ -87,13 +88,13 @@ export class Serializer implements vscode.NotebookSerializer { const isSupported = Object.keys(executor).includes(s.language || '') if (s.lines && isSupported) { const lines = s.lines.join('\n') - const language = s.language === 'shell' ? 'sh' : s.language + const language = normalizeLanguage(s.language) const cell = new vscode.NotebookCellData( vscode.NotebookCellKind.Code, /** * for JS content we want to keep indentation */ - LANGUAGES_WITH_INDENTATION.includes(s.language || '') + LANGUAGES_WITH_INDENTATION.includes(language || '') ? (s.content || '').trim() : lines.trim(), /** diff --git a/src/extension/utils.ts b/src/extension/utils.ts index f051647ce..67a31ee65 100644 --- a/src/extension/utils.ts +++ b/src/extension/utils.ts @@ -81,3 +81,13 @@ export function getCmdShellSeq(cellText: string, os: string): string { return `set -e; ${trimmed}` } + +export function normalizeLanguage(l?: string) { + switch (l) { + case 'zsh': + case 'shell': + return 'sh' + default: + return l + } +} diff --git a/tests/extension/utilts.test.ts b/tests/extension/utilts.test.ts index 702766e02..0a17073bd 100644 --- a/tests/extension/utilts.test.ts +++ b/tests/extension/utilts.test.ts @@ -8,6 +8,7 @@ import { resetEnv, getKey, getCmdShellSeq, + normalizeLanguage, } from '../../src/extension/utils' import { ENV_STORE, DEFAULT_ENV } from '../../src/extension/constants' @@ -124,3 +125,19 @@ suite('getCmdShellSeq', () => { }) }) +suite('normalizeLanguage', () => { + test('with zsh', () => { + const lang = normalizeLanguage('zsh') + expect(lang).toBe('sh') + }) + + test('with shell', () => { + const lang = normalizeLanguage('shell') + expect(lang).toBe('sh') + }) + + test('with sh', () => { + const lang = normalizeLanguage('sh') + expect(lang).toBe('sh') + }) +})