Skip to content

Commit ae49edc

Browse files
committed
Small fix
1 parent 6ccc955 commit ae49edc

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

packages/core/src/editor/managers/ExtensionManager/extensions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ export function getDefaultExtensions(
175175
ShowSelectionExtension(options),
176176
SideMenuExtension(options),
177177
SuggestionMenu(options),
178-
SyntaxHighlightingExtension(options.syntaxHighlighting),
179178
...(options.trailingBlock !== false ? [TrailingNodeExtension()] : []),
180179
] as ExtensionFactoryInstance[];
181180

181+
if (options.syntaxHighlighting) {
182+
extensions.push(SyntaxHighlightingExtension(options.syntaxHighlighting));
183+
}
184+
182185
if (options.collaboration) {
183186
extensions.push(CollaborationExtension(options.collaboration));
184187
} else {

packages/core/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ describe("SyntaxHighlightingExtension", () => {
2323
SyntaxHighlightingExtension(options)({ editor: fakeEditor() })
2424
.prosemirrorPlugins;
2525

26+
// Whether highlighting is enabled at all is decided by the editor (it only
27+
// instantiates this extension when the `syntaxHighlighting` option is set), so
28+
// the extension itself always installs the plugin once created.
2629
it("installs a highlight plugin when a highlighter is configured", () => {
2730
const plugins = pluginsFor({ createHighlighter: async () => ({}) as any });
2831

2932
expect(plugins).toHaveLength(1);
3033
});
3134

32-
it("installs no plugin when no highlighter is configured", () => {
33-
expect(pluginsFor(undefined)).toHaveLength(0);
34-
expect(pluginsFor({})).toHaveLength(0);
35+
it("installs the plugin even without a highlighter (it no-ops at parse time)", () => {
36+
expect(pluginsFor({})).toHaveLength(1);
3537
});
3638
});

packages/core/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,11 @@ export const defaultHighlightBlock = (block: Block<any, any, any>) =>
3636
* blocks get highlighted (and as which language) is decided by the
3737
* `highlightBlock` option, so individual blocks don't configure it themselves.
3838
*
39-
* Highlighting is opt-in: the plugin is only installed when a `createHighlighter`
40-
* is configured.
39+
* Highlighting is opt-in: this extension is only instantiated when the
40+
* `syntaxHighlighting` option is configured (see `getDefaultExtensions`).
4141
*/
4242
export const SyntaxHighlightingExtension = createExtension(
43-
({
44-
editor,
45-
options,
46-
}: ExtensionOptions<SyntaxHighlightingOptions | undefined>) => {
47-
if (!options?.createHighlighter) {
48-
return { key: "syntaxHighlighting", prosemirrorPlugins: [] };
49-
}
50-
43+
({ editor, options }: ExtensionOptions<SyntaxHighlightingOptions>) => {
5144
const highlightBlock = options.highlightBlock ?? defaultHighlightBlock;
5245

5346
// Every block with inline (text) content is a candidate; `highlightBlock`

0 commit comments

Comments
 (0)