Skip to content

Commit 8f08fa1

Browse files
committed
feat(code-editor): add HTML and CSS syntax highlighting support
1 parent df3fd19 commit 8f08fa1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

etc/lime-elements.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ export interface Label<T = LabelValue> {
20882088
export type LabelValue = string | number | boolean | null | undefined;
20892089

20902090
// @public (undocumented)
2091-
export type Language = 'javascript' | 'jinja2' | 'json' | 'typescript';
2091+
export type Language = 'css' | 'html' | 'javascript' | 'jinja2' | 'json' | 'typescript';
20922092

20932093
// @public (undocumented)
20942094
export type Languages = 'da' | 'de' | 'en' | 'fi' | 'fr' | 'nb' | 'no' | 'nl' | 'sv';

src/components/code-editor/code-editor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import {
1010
} from '@stencil/core';
1111
import { ColorScheme, Language } from './code-editor.types';
1212
import CodeMirror from 'codemirror';
13+
import 'codemirror/mode/css/css';
14+
import 'codemirror/mode/htmlmixed/htmlmixed';
1315
import 'codemirror/mode/javascript/javascript';
1416
import 'codemirror/mode/jinja2/jinja2';
1517
import 'codemirror/addon/selection/active-line';
1618
import 'codemirror/addon/edit/matchbrackets';
19+
import 'codemirror/addon/edit/matchtags';
1720
import 'codemirror/addon/lint/lint';
1821
import 'codemirror/addon/lint/json-lint';
1922
import 'codemirror/addon/fold/foldgutter';
2023
import 'codemirror/addon/fold/brace-fold';
24+
import 'codemirror/addon/fold/xml-fold';
2125
import jslint from 'jsonlint-mod';
2226

2327
/**
@@ -208,6 +212,8 @@ export class CodeEditor {
208212
name: 'application/typescript',
209213
typescript: true,
210214
};
215+
} else if (this.language === 'html') {
216+
mode = 'htmlmixed';
211217
}
212218

213219
if (this.fold) {
@@ -224,6 +230,7 @@ export class CodeEditor {
224230
lineNumbers: this.lineNumbers,
225231
styleActiveLine: true,
226232
matchBrackets: true,
233+
matchTags: { bothTags: true },
227234
lint: this.lint,
228235
foldGutter: this.fold,
229236
gutters: gutters,

src/components/code-editor/code-editor.types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/**
22
* @public
33
*/
4-
export type Language = 'javascript' | 'jinja2' | 'json' | 'typescript';
4+
export type Language =
5+
| 'css'
6+
| 'html'
7+
| 'javascript'
8+
| 'jinja2'
9+
| 'json'
10+
| 'typescript';
511

612
/**
713
* @public

0 commit comments

Comments
 (0)