@atlaskit/editor-plugin-code-block-advanced 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 2.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149738](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/149738)
8
+ [`3098e65159385`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3098e65159385) -
9
+ Fix selection when the editor is disabled.
10
+
11
+ ## 2.2.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#142712](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142712)
16
+ [`6eb10c572bdad`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6eb10c572bdad) -
17
+ [ux] Improve syntax highlighting for yaml.
18
+ - Updated dependencies
19
+
3
20
  ## 2.2.2
4
21
 
5
22
  ### Patch Changes
@@ -76,7 +76,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
76
76
  fixed: false
77
77
  }), _view.EditorView.updateListener.of(function (update) {
78
78
  return _this.forwardUpdate(update);
79
- }), this.readOnlyCompartment.of(_view.EditorView.editable.of(this.view.editable)), (0, _autocomplete.closeBrackets)(), _view.EditorView.editorAttributes.of({
79
+ }), this.readOnlyCompartment.of([_state.EditorState.readOnly.of(!this.view.editable), _view.EditorView.contentAttributes.of({
80
+ contentEditable: "".concat(this.view.editable)
81
+ })]), (0, _autocomplete.closeBrackets)(), _view.EditorView.editorAttributes.of({
80
82
  class: 'code-block'
81
83
  }), (0, _manageSelectionMarker.manageSelectionMarker)(config.api), (0, _prosemirrorDecorations.prosemirrorDecorationPlugin)(this.pmFacet, view, getPos)])
82
84
  });
@@ -141,7 +143,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
141
143
  value: function updateReadonlyState() {
142
144
  this.updating = true;
143
145
  this.cm.dispatch({
144
- effects: this.readOnlyCompartment.reconfigure(_view.EditorView.editable.of(this.view.editable))
146
+ effects: this.readOnlyCompartment.reconfigure([_state.EditorState.readOnly.of(!this.view.editable), _view.EditorView.contentAttributes.of({
147
+ contentEditable: "".concat(this.view.editable)
148
+ })])
145
149
  });
146
150
  this.updating = false;
147
151
  }
@@ -8,6 +8,8 @@ exports.LanguageLoader = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _language = require("@codemirror/language");
12
+ var _syntaxHighlightingTheme = require("../../ui/syntaxHighlightingTheme");
11
13
  var _languageMap = require("./languageMap");
12
14
  /**
13
15
  * Manages loading the languages (for syntax highlighting, etc.)
@@ -37,7 +39,12 @@ var LanguageLoader = exports.LanguageLoader = /*#__PURE__*/function () {
37
39
  }
38
40
  language.load().then(function (lang) {
39
41
  if (lang) {
40
- _this.updateLanguageCompartment(lang);
42
+ var styling = (0, _syntaxHighlightingTheme.languageStyling)(lang.language);
43
+ if (styling) {
44
+ _this.updateLanguageCompartment([lang, (0, _language.syntaxHighlighting)(styling)]);
45
+ } else {
46
+ _this.updateLanguageCompartment(lang);
47
+ }
41
48
  _this.languageName = languageName;
42
49
  } else {
43
50
  configureEmpty();
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.highlightStyle = void 0;
6
+ exports.languageStyling = exports.highlightStyle = void 0;
7
7
  var _language = require("@codemirror/language");
8
8
  var _highlight = require("@lezer/highlight");
9
9
  // Based on `platform/packages/design-system/code/src/internal/theme/styles.tsx`
@@ -76,4 +76,28 @@ var highlightStyle = exports.highlightStyle = _language.HighlightStyle.define([{
76
76
  }, {
77
77
  tag: _highlight.tags.invalid,
78
78
  color: "var(--ds-text, #172B4D)"
79
- }]);
79
+ }]);
80
+
81
+ /**
82
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
83
+ * Occasionally we may want to override tokens for certain languages to
84
+ * get closer to renderer.
85
+ *
86
+ * Note the way that codemirror works - these styles get added on top of the styling above
87
+ * (and override existing tags).
88
+ *
89
+ * @param language Codemirror language to scope the changes to a specific language
90
+ * @returns Highlight style which can be used with the syntax highlighting extension
91
+ */
92
+ var languageStyling = exports.languageStyling = function languageStyling(language) {
93
+ switch (language.name) {
94
+ case 'yaml':
95
+ return _language.HighlightStyle.define([{
96
+ tag: _highlight.tags.definition(_highlight.tags.propertyName),
97
+ color: "var(--ds-text-accent-green, #216E4E)",
98
+ fontWeight: "var(--ds-font-weight-bold, 700)"
99
+ }], {
100
+ scope: language
101
+ });
102
+ }
103
+ };
@@ -26,6 +26,9 @@ var cmTheme = exports.cmTheme = _view.EditorView.theme({
26
26
  '&.cm-editor.code-block.danger': {
27
27
  backgroundColor: "var(--ds-background-danger, #FFECEB)"
28
28
  },
29
+ '.cm-content[aria-readonly="true"]': {
30
+ caretColor: 'transparent'
31
+ },
29
32
  '.cm-content': {
30
33
  cursor: 'text',
31
34
  caretColor: "var(--ds-text, #172B4D)",
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { closeBrackets } from '@codemirror/autocomplete';
3
3
  import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
4
- import { Compartment, EditorSelection, Facet } from '@codemirror/state';
4
+ import { Compartment, EditorSelection, Facet, EditorState as CodeMirrorState } from '@codemirror/state';
5
5
  import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
6
6
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
7
7
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
@@ -56,7 +56,9 @@ class CodeBlockAdvancedNodeView {
56
56
  // Renderer behaviour
57
57
  gutters({
58
58
  fixed: false
59
- }), CodeMirror.updateListener.of(update => this.forwardUpdate(update)), this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)), closeBrackets(), CodeMirror.editorAttributes.of({
59
+ }), CodeMirror.updateListener.of(update => this.forwardUpdate(update)), this.readOnlyCompartment.of([CodeMirrorState.readOnly.of(!this.view.editable), CodeMirror.contentAttributes.of({
60
+ contentEditable: `${this.view.editable}`
61
+ })]), closeBrackets(), CodeMirror.editorAttributes.of({
60
62
  class: 'code-block'
61
63
  }), manageSelectionMarker(config.api), prosemirrorDecorationPlugin(this.pmFacet, view, getPos)]
62
64
  });
@@ -113,7 +115,9 @@ class CodeBlockAdvancedNodeView {
113
115
  updateReadonlyState() {
114
116
  this.updating = true;
115
117
  this.cm.dispatch({
116
- effects: this.readOnlyCompartment.reconfigure(CodeMirror.editable.of(this.view.editable))
118
+ effects: this.readOnlyCompartment.reconfigure([CodeMirrorState.readOnly.of(!this.view.editable), CodeMirror.contentAttributes.of({
119
+ contentEditable: `${this.view.editable}`
120
+ })])
117
121
  });
118
122
  this.updating = false;
119
123
  }
@@ -1,4 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { syntaxHighlighting } from '@codemirror/language';
3
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
2
4
  import { mapLanguageToCodeMirror } from './languageMap';
3
5
 
4
6
  /**
@@ -25,7 +27,12 @@ export class LanguageLoader {
25
27
  }
26
28
  language.load().then(lang => {
27
29
  if (lang) {
28
- this.updateLanguageCompartment(lang);
30
+ const styling = languageStyling(lang.language);
31
+ if (styling) {
32
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
33
+ } else {
34
+ this.updateLanguageCompartment(lang);
35
+ }
29
36
  this.languageName = languageName;
30
37
  } else {
31
38
  configureEmpty();
@@ -70,4 +70,28 @@ export const highlightStyle = HighlightStyle.define([{
70
70
  }, {
71
71
  tag: tags.invalid,
72
72
  color: "var(--ds-text, #172B4D)"
73
- }]);
73
+ }]);
74
+
75
+ /**
76
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
77
+ * Occasionally we may want to override tokens for certain languages to
78
+ * get closer to renderer.
79
+ *
80
+ * Note the way that codemirror works - these styles get added on top of the styling above
81
+ * (and override existing tags).
82
+ *
83
+ * @param language Codemirror language to scope the changes to a specific language
84
+ * @returns Highlight style which can be used with the syntax highlighting extension
85
+ */
86
+ export const languageStyling = language => {
87
+ switch (language.name) {
88
+ case 'yaml':
89
+ return HighlightStyle.define([{
90
+ tag: tags.definition(tags.propertyName),
91
+ color: "var(--ds-text-accent-green, #216E4E)",
92
+ fontWeight: "var(--ds-font-weight-bold, 700)"
93
+ }], {
94
+ scope: language
95
+ });
96
+ }
97
+ };
@@ -20,6 +20,9 @@ export const cmTheme = CodeMirror.theme({
20
20
  '&.cm-editor.code-block.danger': {
21
21
  backgroundColor: "var(--ds-background-danger, #FFECEB)"
22
22
  },
23
+ '.cm-content[aria-readonly="true"]': {
24
+ caretColor: 'transparent'
25
+ },
23
26
  '.cm-content': {
24
27
  cursor: 'text',
25
28
  caretColor: "var(--ds-text, #172B4D)",
@@ -4,7 +4,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import { closeBrackets } from '@codemirror/autocomplete';
6
6
  import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
7
- import { Compartment, EditorSelection, Facet } from '@codemirror/state';
7
+ import { Compartment, EditorSelection, Facet, EditorState as CodeMirrorState } from '@codemirror/state';
8
8
  import { EditorView as CodeMirror, lineNumbers, gutters } from '@codemirror/view';
9
9
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
10
10
  import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
@@ -69,7 +69,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
69
69
  fixed: false
70
70
  }), CodeMirror.updateListener.of(function (update) {
71
71
  return _this.forwardUpdate(update);
72
- }), this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)), closeBrackets(), CodeMirror.editorAttributes.of({
72
+ }), this.readOnlyCompartment.of([CodeMirrorState.readOnly.of(!this.view.editable), CodeMirror.contentAttributes.of({
73
+ contentEditable: "".concat(this.view.editable)
74
+ })]), closeBrackets(), CodeMirror.editorAttributes.of({
73
75
  class: 'code-block'
74
76
  }), manageSelectionMarker(config.api), prosemirrorDecorationPlugin(this.pmFacet, view, getPos)])
75
77
  });
@@ -134,7 +136,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
134
136
  value: function updateReadonlyState() {
135
137
  this.updating = true;
136
138
  this.cm.dispatch({
137
- effects: this.readOnlyCompartment.reconfigure(CodeMirror.editable.of(this.view.editable))
139
+ effects: this.readOnlyCompartment.reconfigure([CodeMirrorState.readOnly.of(!this.view.editable), CodeMirror.contentAttributes.of({
140
+ contentEditable: "".concat(this.view.editable)
141
+ })])
138
142
  });
139
143
  this.updating = false;
140
144
  }
@@ -1,6 +1,8 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import { syntaxHighlighting } from '@codemirror/language';
5
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
4
6
  import { mapLanguageToCodeMirror } from './languageMap';
5
7
 
6
8
  /**
@@ -31,7 +33,12 @@ export var LanguageLoader = /*#__PURE__*/function () {
31
33
  }
32
34
  language.load().then(function (lang) {
33
35
  if (lang) {
34
- _this.updateLanguageCompartment(lang);
36
+ var styling = languageStyling(lang.language);
37
+ if (styling) {
38
+ _this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
39
+ } else {
40
+ _this.updateLanguageCompartment(lang);
41
+ }
35
42
  _this.languageName = languageName;
36
43
  } else {
37
44
  configureEmpty();
@@ -70,4 +70,28 @@ export var highlightStyle = HighlightStyle.define([{
70
70
  }, {
71
71
  tag: tags.invalid,
72
72
  color: "var(--ds-text, #172B4D)"
73
- }]);
73
+ }]);
74
+
75
+ /**
76
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
77
+ * Occasionally we may want to override tokens for certain languages to
78
+ * get closer to renderer.
79
+ *
80
+ * Note the way that codemirror works - these styles get added on top of the styling above
81
+ * (and override existing tags).
82
+ *
83
+ * @param language Codemirror language to scope the changes to a specific language
84
+ * @returns Highlight style which can be used with the syntax highlighting extension
85
+ */
86
+ export var languageStyling = function languageStyling(language) {
87
+ switch (language.name) {
88
+ case 'yaml':
89
+ return HighlightStyle.define([{
90
+ tag: tags.definition(tags.propertyName),
91
+ color: "var(--ds-text-accent-green, #216E4E)",
92
+ fontWeight: "var(--ds-font-weight-bold, 700)"
93
+ }], {
94
+ scope: language
95
+ });
96
+ }
97
+ };
@@ -20,6 +20,9 @@ export var cmTheme = CodeMirror.theme({
20
20
  '&.cm-editor.code-block.danger': {
21
21
  backgroundColor: "var(--ds-background-danger, #FFECEB)"
22
22
  },
23
+ '.cm-content[aria-readonly="true"]': {
24
+ caretColor: 'transparent'
25
+ },
23
26
  '.cm-content': {
24
27
  cursor: 'text',
25
28
  caretColor: "var(--ds-text, #172B4D)",
@@ -1,4 +1,5 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
2
3
  /**
3
4
  * Manages loading the languages (for syntax highlighting, etc.)
4
5
  * from CodeMirror and updating the language in the CodeMirror view
@@ -6,6 +7,6 @@ import { LanguageSupport } from '@codemirror/language';
6
7
  export declare class LanguageLoader {
7
8
  private updateLanguageCompartment;
8
9
  private languageName;
9
- constructor(updateLanguageCompartment: (value: LanguageSupport | []) => void);
10
+ constructor(updateLanguageCompartment: (value: LanguageSupport | [LanguageSupport, Extension] | []) => void);
10
11
  updateLanguage(languageName: string): void;
11
12
  }
@@ -1,2 +1,14 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  export declare const highlightStyle: HighlightStyle;
3
+ /**
4
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
5
+ * Occasionally we may want to override tokens for certain languages to
6
+ * get closer to renderer.
7
+ *
8
+ * Note the way that codemirror works - these styles get added on top of the styling above
9
+ * (and override existing tags).
10
+ *
11
+ * @param language Codemirror language to scope the changes to a specific language
12
+ * @returns Highlight style which can be used with the syntax highlighting extension
13
+ */
14
+ export declare const languageStyling: (language: Language) => HighlightStyle | undefined;
@@ -1,4 +1,5 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
2
3
  /**
3
4
  * Manages loading the languages (for syntax highlighting, etc.)
4
5
  * from CodeMirror and updating the language in the CodeMirror view
@@ -7,6 +8,9 @@ export declare class LanguageLoader {
7
8
  private updateLanguageCompartment;
8
9
  private languageName;
9
10
  constructor(updateLanguageCompartment: (value: LanguageSupport | [
11
+ LanguageSupport,
12
+ Extension
13
+ ] | [
10
14
  ]) => void);
11
15
  updateLanguage(languageName: string): void;
12
16
  }
@@ -1,2 +1,14 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  export declare const highlightStyle: HighlightStyle;
3
+ /**
4
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
5
+ * Occasionally we may want to override tokens for certain languages to
6
+ * get closer to renderer.
7
+ *
8
+ * Note the way that codemirror works - these styles get added on top of the styling above
9
+ * (and override existing tags).
10
+ *
11
+ * @param language Codemirror language to scope the changes to a specific language
12
+ * @returns Highlight style which can be used with the syntax highlighting extension
13
+ */
14
+ export declare const languageStyling: (language: Language) => HighlightStyle | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block-advanced",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,14 +33,14 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^47.6.0",
36
- "@atlaskit/editor-common": "^103.3.0",
37
- "@atlaskit/editor-plugin-code-block": "^4.2.0",
36
+ "@atlaskit/editor-common": "^103.22.0",
37
+ "@atlaskit/editor-plugin-code-block": "^4.4.0",
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
39
- "@atlaskit/editor-plugin-find-replace": "^2.0.0",
40
- "@atlaskit/editor-plugin-selection": "^2.1.0",
41
- "@atlaskit/editor-plugin-selection-marker": "^2.1.0",
39
+ "@atlaskit/editor-plugin-find-replace": "^2.2.0",
40
+ "@atlaskit/editor-plugin-selection": "^2.2.0",
41
+ "@atlaskit/editor-plugin-selection-marker": "^2.2.0",
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
- "@atlaskit/tokens": "^4.7.0",
43
+ "@atlaskit/tokens": "^4.8.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@codemirror/autocomplete": "6.18.4",
46
46
  "@codemirror/commands": "6.7.1",
@@ -57,7 +57,7 @@
57
57
  "react": "^18.2.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@atlaskit/code": "^17.0.0",
60
+ "@atlaskit/code": "^17.1.0",
61
61
  "typescript": "~5.4.2"
62
62
  },
63
63
  "techstack": {
@@ -1,6 +1,12 @@
1
1
  import { closeBrackets } from '@codemirror/autocomplete';
2
2
  import { syntaxHighlighting, bracketMatching } from '@codemirror/language';
3
- import { Compartment, Extension, EditorSelection, Facet } from '@codemirror/state';
3
+ import {
4
+ Compartment,
5
+ Extension,
6
+ EditorSelection,
7
+ Facet,
8
+ EditorState as CodeMirrorState,
9
+ } from '@codemirror/state';
4
10
  import { EditorView as CodeMirror, lineNumbers, ViewUpdate, gutters } from '@codemirror/view';
5
11
 
6
12
  import { isCodeBlockWordWrapEnabled } from '@atlaskit/editor-common/code-block';
@@ -103,7 +109,10 @@ class CodeBlockAdvancedNodeView implements NodeView {
103
109
  // Renderer behaviour
104
110
  gutters({ fixed: false }),
105
111
  CodeMirror.updateListener.of((update) => this.forwardUpdate(update)),
106
- this.readOnlyCompartment.of(CodeMirror.editable.of(this.view.editable)),
112
+ this.readOnlyCompartment.of([
113
+ CodeMirrorState.readOnly.of(!this.view.editable),
114
+ CodeMirror.contentAttributes.of({ contentEditable: `${this.view.editable}` }),
115
+ ]),
107
116
  closeBrackets(),
108
117
  CodeMirror.editorAttributes.of({ class: 'code-block' }),
109
118
  manageSelectionMarker(config.api),
@@ -161,7 +170,10 @@ class CodeBlockAdvancedNodeView implements NodeView {
161
170
  private updateReadonlyState() {
162
171
  this.updating = true;
163
172
  this.cm.dispatch({
164
- effects: this.readOnlyCompartment.reconfigure(CodeMirror.editable.of(this.view.editable)),
173
+ effects: this.readOnlyCompartment.reconfigure([
174
+ CodeMirrorState.readOnly.of(!this.view.editable),
175
+ CodeMirror.contentAttributes.of({ contentEditable: `${this.view.editable}` }),
176
+ ]),
165
177
  });
166
178
  this.updating = false;
167
179
  }
@@ -1,4 +1,7 @@
1
- import { LanguageSupport } from '@codemirror/language';
1
+ import { LanguageSupport, syntaxHighlighting } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
3
+
4
+ import { languageStyling } from '../../ui/syntaxHighlightingTheme';
2
5
 
3
6
  import { mapLanguageToCodeMirror } from './languageMap';
4
7
 
@@ -9,7 +12,11 @@ import { mapLanguageToCodeMirror } from './languageMap';
9
12
  export class LanguageLoader {
10
13
  private languageName: string = '';
11
14
 
12
- constructor(private updateLanguageCompartment: (value: LanguageSupport | []) => void) {}
15
+ constructor(
16
+ private updateLanguageCompartment: (
17
+ value: LanguageSupport | [LanguageSupport, Extension] | [],
18
+ ) => void,
19
+ ) {}
13
20
 
14
21
  updateLanguage(languageName: string) {
15
22
  if (languageName === this.languageName) {
@@ -31,7 +38,12 @@ export class LanguageLoader {
31
38
  .load()
32
39
  .then((lang) => {
33
40
  if (lang) {
34
- this.updateLanguageCompartment(lang);
41
+ const styling = languageStyling(lang.language);
42
+ if (styling) {
43
+ this.updateLanguageCompartment([lang, syntaxHighlighting(styling)]);
44
+ } else {
45
+ this.updateLanguageCompartment(lang);
46
+ }
35
47
  this.languageName = languageName;
36
48
  } else {
37
49
  configureEmpty();
@@ -1,4 +1,4 @@
1
- import { HighlightStyle } from '@codemirror/language';
1
+ import { HighlightStyle, Language } from '@codemirror/language';
2
2
  import { tags } from '@lezer/highlight';
3
3
 
4
4
  import { token } from '@atlaskit/tokens';
@@ -55,3 +55,32 @@ export const highlightStyle = HighlightStyle.define([
55
55
  { tag: tags.comment, color: token('color.text.subtlest'), fontStyle: 'italic' },
56
56
  { tag: tags.invalid, color: token('color.text') },
57
57
  ]);
58
+
59
+ /**
60
+ * Prismjs (renderer) and codemirror (editor) tokenise slightly differently,
61
+ * Occasionally we may want to override tokens for certain languages to
62
+ * get closer to renderer.
63
+ *
64
+ * Note the way that codemirror works - these styles get added on top of the styling above
65
+ * (and override existing tags).
66
+ *
67
+ * @param language Codemirror language to scope the changes to a specific language
68
+ * @returns Highlight style which can be used with the syntax highlighting extension
69
+ */
70
+ export const languageStyling = (language: Language): HighlightStyle | undefined => {
71
+ switch (language.name) {
72
+ case 'yaml':
73
+ return HighlightStyle.define(
74
+ [
75
+ {
76
+ tag: tags.definition(tags.propertyName),
77
+ color: token('color.text.accent.green'),
78
+ fontWeight: token('font.weight.bold'),
79
+ },
80
+ ],
81
+ {
82
+ scope: language,
83
+ },
84
+ );
85
+ }
86
+ };
package/src/ui/theme.ts CHANGED
@@ -23,6 +23,9 @@ export const cmTheme = CodeMirror.theme({
23
23
  '&.cm-editor.code-block.danger': {
24
24
  backgroundColor: token('color.background.danger'),
25
25
  },
26
+ '.cm-content[aria-readonly="true"]': {
27
+ caretColor: 'transparent',
28
+ },
26
29
  '.cm-content': {
27
30
  cursor: 'text',
28
31
  caretColor: token('color.text'),