Skip to content

Commit 6962e80

Browse files
authored
UBERF-8560 Imrove editor code highlight (#7074)
1 parent 1b02810 commit 6962e80

File tree

21 files changed

+423
-43
lines changed

21 files changed

+423
-43
lines changed

common/config/rush/pnpm-lock.yaml

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

packages/highlight/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
extends: ['./node_modules/@hcengineering/platform-rig/profiles/ui/eslint.config.json'],
3+
parserOptions: { tsconfigRootDir: __dirname }
4+
}

packages/highlight/.prettierrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"trailingComma": "none",
4+
"tabWidth": 2,
5+
"semi": false,
6+
"singleQuote": true,
7+
"printWidth": 120,
8+
"useTabs": false,
9+
"bracketSpacing": true,
10+
"proseWrap": "preserve",
11+
"plugins": [
12+
"prettier-plugin-svelte"
13+
],
14+
"overrides": [
15+
{
16+
"files": "*.svelte",
17+
"options": {
18+
"parser": "svelte"
19+
}
20+
}
21+
]
22+
}

packages/highlight/config/rig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
3+
"rigPackageName": "@hcengineering/platform-rig",
4+
"rigProfile": "ui"
5+
}

packages/highlight/jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
5+
roots: ["./src"],
6+
coverageReporters: ["text-summary", "html"]
7+
}

packages/highlight/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@hcengineering/highlight",
3+
"version": "0.6.0",
4+
"main": "src/index.ts",
5+
"author": "Hardcore Engineering Inc.",
6+
"license": "EPL-2.0",
7+
"scripts": {
8+
"build": "compile ui",
9+
"build:docs": "api-extractor run --local",
10+
"format": "format src",
11+
"svelte-check": "do-svelte-check",
12+
"_phase:svelte-check": "do-svelte-check",
13+
"build:watch": "compile ui",
14+
"_phase:build": "compile ui",
15+
"_phase:format": "format src",
16+
"_phase:validate": "compile validate"
17+
},
18+
"devDependencies": {
19+
"svelte-loader": "^3.2.0",
20+
"sass": "^1.53.0",
21+
"svelte-preprocess": "^5.1.3",
22+
"@hcengineering/platform-rig": "^0.6.0",
23+
"@typescript-eslint/eslint-plugin": "^6.11.0",
24+
"@typescript-eslint/parser": "^6.11.0",
25+
"eslint-config-standard-with-typescript": "^40.0.0",
26+
"eslint-plugin-import": "^2.26.0",
27+
"eslint-plugin-n": "^15.4.0",
28+
"eslint-plugin-promise": "^6.1.1",
29+
"prettier-plugin-svelte": "^3.2.2",
30+
"eslint": "^8.54.0",
31+
"prettier": "^3.1.0",
32+
"svelte-check": "^3.6.9",
33+
"typescript": "^5.3.3",
34+
"jest": "^29.7.0",
35+
"ts-jest": "^29.1.1",
36+
"@types/jest": "^29.5.5",
37+
"eslint-plugin-svelte": "^2.35.1",
38+
"svelte-eslint-parser": "^0.33.1"
39+
},
40+
"dependencies": {
41+
"svelte": "^4.2.12",
42+
"@hcengineering/ui": "^0.6.15",
43+
"highlight.js": "~11.8.0",
44+
"lowlight": "^3.1.0"
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: [
3+
require('autoprefixer')
4+
]
5+
}

plugins/diffview-resources/src/highlight/highlight.ts renamed to packages/highlight/src/index.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright © 2023 Hardcore Engineering Inc.
2+
// Copyright © 2024 Hardcore Engineering Inc.
33
//
44
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License. You may
@@ -13,16 +13,29 @@
1313
// limitations under the License.
1414
//
1515

16-
import hljs from 'highlight.js'
17-
import { hljsDefineSvelte } from './languages/svelte-hljs'
16+
import hljs, { type LanguageFn } from 'highlight.js'
17+
import { all } from 'lowlight'
18+
import { svelte } from './languages/svelte'
19+
import { vlang } from './languages/vlang'
1820

19-
hljs.registerLanguage('svelte', hljsDefineSvelte)
21+
/** @public */
22+
export const grammars: Record<string, LanguageFn> = {
23+
...all,
24+
svelte,
25+
vlang
26+
}
27+
28+
Object.entries(grammars).forEach((grammar) => {
29+
hljs.registerLanguage(...grammar)
30+
})
2031

32+
/** @public */
2133
export interface HighlightOptions {
2234
auto?: boolean
2335
language: string | undefined
2436
}
2537

38+
/** @public */
2639
export function highlightText (text: string, options: HighlightOptions): string {
2740
// We should always use highlighter because it sanitizes the input
2841
// We have to always use highlighter to ensure that the input is sanitized
@@ -38,6 +51,7 @@ export function highlightText (text: string, options: HighlightOptions): string
3851
return normalizeHighlightTags(highlighted)
3952
}
4053

54+
/** @public */
4155
export function highlightLines (lines: string[], options: HighlightOptions): string[] {
4256
const highlighted = highlightText(lines.join('\n'), options)
4357
return highlighted.split('\n')
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
export function hljsDefineSvelte (hljs: any): any {
1+
//
2+
// Copyright © 2024 Hardcore Engineering Inc.
3+
//
4+
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License. You may
6+
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
export function svelte (hljs: any): any {
217
return {
318
subLanguage: 'xml',
419
contains: [

0 commit comments

Comments
 (0)