Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/blocks/Code/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ describe("Code block input rule", () => {
expect((block.props as any).language).toBe("ts");
});

it("converts ``` + space into a codeBlock with empty language", () => {
it("converts ``` + space into a codeBlock with the default language", () => {
typeString(editor, "``` ");

const block = editor.document[0];
expect(block.type).toBe("codeBlock");
expect((block.props as any).language).toBe("");
expect((block.props as any).language).toBe("text");
});

it("converts ```javascript + space into a codeBlock", () => {
Expand Down Expand Up @@ -138,13 +138,13 @@ describe("Code block input rule", () => {
expect(block.content).toEqual([]);
});

it("converts ``` + Enter into a codeBlock with empty language", () => {
it("converts ``` + Enter into a codeBlock with the default language", () => {
typeString(editor, "```");
pressKey(editor, "Enter");

const block = editor.document[0];
expect(block.type).toBe("codeBlock");
expect((block.props as any).language).toBe("");
expect((block.props as any).language).toBe("text");
});

it("converts ```javascript + Enter into a codeBlock", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ export const CodeKeyboardShortcutsExtension =
find: /^```(.*?)\s$/,
replace: ({ match }) => {
const languageName = match[1].trim();
// Without a language suffix there is nothing to resolve, so fall
// back to the default rather than storing an empty language that
// no highlighter can render.
const attributes = {
language: getLanguageId(options, languageName) ?? languageName,
language:
getLanguageId(options, languageName) ??
(languageName || options.defaultLanguage || "text"),
};

return {
Expand Down
Loading