Skip to content

Commit 06dbbb8

Browse files
authored
Merge branch 'main' into update(CodeBlock)/updated-new-code-paste
2 parents 26c4ac5 + e4fd657 commit 06dbbb8

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [15.27.2](https://github.com/gravity-ui/markdown-editor/compare/v15.27.1...v15.27.2) (2025-12-19)
4+
5+
6+
### Bug Fixes
7+
8+
* **CodeBlock:** apply syntax highlighting on initial render ([#902](https://github.com/gravity-ui/markdown-editor/issues/902)) ([87d7d98](https://github.com/gravity-ui/markdown-editor/commit/87d7d981e7a2815ecae5d11bd0170abdfee5c45f))
9+
310
## [15.27.1](https://github.com/gravity-ui/markdown-editor/compare/v15.27.0...v15.27.1) (2025-12-12)
411

512

demo/stories/markdown/markup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Sample text here...
252252
253253
Syntax highlighting
254254
255-
\`\`\` js
255+
\`\`\`javascript
256256
var foo = function (bar) {
257257
return bar++;
258258
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gravity-ui/markdown-editor",
3-
"version": "15.27.1",
3+
"version": "15.27.2",
44
"description": "Markdown wysiwyg and markup editor",
55
"license": "MIT",
66
"repository": {

src/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Plugin, PluginKey} from 'prosemirror-state';
77
import type {Step} from 'prosemirror-transform';
88
// @ts-ignore // TODO: fix cjs build
99
import {findChildrenByType} from 'prosemirror-utils';
10-
import {Decoration, DecorationSet} from 'prosemirror-view';
10+
import {Decoration, DecorationSet, type EditorView} from 'prosemirror-view';
1111

1212
import type {ExtensionAuto} from '../../../../core';
1313
import {capitalize} from '../../../../lodash';
@@ -64,6 +64,7 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
6464

6565
builder.addPlugin(() => {
6666
let modulesLoaded = false;
67+
let view: EditorView | null = null;
6768

6869
const selectItems: LangSelectItem[] = [];
6970
const mapping: Record<string, string> = {};
@@ -90,6 +91,8 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
9091
}
9192
}
9293
}
94+
95+
view?.dispatch(view.state.tr.setMeta(key, {modulesLoaded}));
9396
}
9497
});
9598
return getDecorations(state.doc);
@@ -99,6 +102,10 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
99102
return DecorationSet.empty;
100103
}
101104

105+
if (tr.getMeta(key)?.modulesLoaded) {
106+
return getDecorations(tr.doc);
107+
}
108+
102109
if (tr.docChanged) {
103110
const oldNodeName = oldState.selection.$head.parent.type.name;
104111
const newNodeName = newState.selection.$head.parent.type.name;
@@ -143,13 +150,15 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
143150
return decos.map(tr.mapping, tr.doc);
144151
},
145152
},
146-
view: (view) =>
147-
codeLangSelectTooltipViewCreator(
153+
view: (v) => {
154+
view = v;
155+
return codeLangSelectTooltipViewCreator(
148156
view,
149157
selectItems,
150158
mapping,
151159
Boolean(opts.lineNumbers?.enabled),
152-
),
160+
);
161+
},
153162
props: {
154163
decorations: (state) => {
155164
return key.getState(state);
4.7 KB
Loading
4.28 KB
Loading

0 commit comments

Comments
 (0)