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

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,14 @@
1
1
  # @atlaskit/editor-plugin-code-block-advanced
2
2
 
3
+ ## 2.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#142712](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142712)
8
+ [`6eb10c572bdad`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6eb10c572bdad) -
9
+ [ux] Improve syntax highlighting for yaml.
10
+ - Updated dependencies
11
+
3
12
  ## 2.2.2
4
13
 
5
14
  ### Patch Changes
@@ -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
+ };
@@ -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
+ };
@@ -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
+ };
@@ -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.3",
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.9.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",
39
+ "@atlaskit/editor-plugin-find-replace": "^2.2.0",
40
40
  "@atlaskit/editor-plugin-selection": "^2.1.0",
41
- "@atlaskit/editor-plugin-selection-marker": "^2.1.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",
@@ -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
+ };