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
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ describe("InitializedMarkdownEditor", () => {
});
});

describe("code blocks", () => {
it("renders existing code blocks in write mode when withCodeBlocks is false", async () => {
// Given
const markdown = "Before\n\n```\nconsole.log('hi');\n```\n\nAfter";

// When / Then — must not throw "Parsing of the following markdown
// structure failed: {type: code, name: N/A}".
await renderWithAct(
<MockedEditorComponent markdown={markdown} mode="write" />
);

const editor = screen.getByLabelText(EDITOR_LABEL);
expect(editor).toHaveTextContent("Before");
expect(editor).toHaveTextContent("After");
});
});

describe("html tags", () => {
it("properly preserves HTML tags with custom attributes", async () => {
// Given
Expand Down
10 changes: 5 additions & 5 deletions front_end/src/components/markdown_editor/initialized_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ const InitializedMarkdownEditor: FC<
equationPlugin(),
];

if (!withCodeBlocks) {
return common;
}

if (mode === "read") {
// Always register codeBlockPlugin so pre-existing ``` fences in the source
// markdown parse — otherwise MDXEditor throws on unknown "code" nodes.
// `withCodeBlocks` only gates the insert-code-block toolbar affordance and
// the rich CodeMirror editing experience.
if (!withCodeBlocks || mode === "read") {
return [
...common,
codeBlockPlugin({
Expand Down
Loading