react-codemirror-runmode 2.1.0 → 2.2.0

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "enableAllProjectMcpServers": false
3
+ }
package/dist/highlight.js CHANGED
@@ -1,8 +1,15 @@
1
1
  import { LanguageDescription } from '@codemirror/language';
2
2
  import { highlightTree } from '@lezer/highlight';
3
3
  import { languages as builtinLanguages } from '@codemirror/language-data';
4
+ import { markdown } from '@codemirror/lang-markdown';
4
5
  export async function getCodeParser(languageName, fallbackLanguage, languages = builtinLanguages) {
5
- if (languageName) {
6
+ if (languageName === 'markdown' || languageName === 'md') {
7
+ const mdSupport = markdown({
8
+ codeLanguages: builtinLanguages
9
+ });
10
+ return mdSupport.language.parser;
11
+ }
12
+ else {
6
13
  const found = LanguageDescription.matchLanguageName(languages, languageName, true);
7
14
  if (found instanceof LanguageDescription) {
8
15
  if (!found.support)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-codemirror-runmode",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Syntax highlighting for react, utilizing CodeMirror's parser",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,6 +14,7 @@
14
14
  "build": "tsc --project tsconfig.build.json",
15
15
  "test": "vitest",
16
16
  "lint": "eslint .",
17
+ "typecheck": "tsc --noEmit",
17
18
  "format": "prettier --write .",
18
19
  "format:check": "prettier --check .",
19
20
  "prepublishOnly": "npm-run-all lint format:check build && npm run test run"
@@ -31,30 +32,31 @@
31
32
  "url": "https://github.com/craftzdog/react-codemirror-runmode.git"
32
33
  },
33
34
  "dependencies": {
34
- "@codemirror/language": "^6.11.0",
35
- "@codemirror/language-data": "^6.5.1",
36
- "@lezer/common": "^1.2.3",
37
- "@lezer/highlight": "^1.2.1"
35
+ "@codemirror/language": "^6.11.3",
36
+ "@codemirror/language-data": "^6.5.2",
37
+ "@lezer/common": "^1.4.0",
38
+ "@lezer/highlight": "^1.2.3"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "react": ">= 18"
41
42
  },
42
43
  "devDependencies": {
43
- "@codemirror/theme-one-dark": "^6.1.2",
44
- "@testing-library/react": "^16.2.0",
45
- "@types/node": "^22.13.10",
46
- "@types/react": "^19.0.12",
47
- "@vitejs/plugin-react": "^4.3.4",
48
- "eslint": "^9.22.0",
49
- "eslint-config-prettier": "^10.1.1",
50
- "eslint-plugin-react": "^7.37.4",
51
- "jsdom": "^26.0.0",
44
+ "@codemirror/theme-one-dark": "^6.1.3",
45
+ "@testing-library/react": "^16.3.0",
46
+ "@types/node": "^25.0.1",
47
+ "@types/react": "^19.2.7",
48
+ "@vitejs/plugin-react": "^5.1.2",
49
+ "eslint": "^9.39.1",
50
+ "eslint-config-prettier": "^10.1.8",
51
+ "eslint-plugin-react": "^7.37.5",
52
+ "jsdom": "^27.3.0",
52
53
  "npm-run-all": "^4.1.5",
53
- "prettier": "^3.5.3",
54
- "react": "^19.0.0",
55
- "typescript": "^5.8.2",
56
- "typescript-eslint": "^8.27.0",
57
- "vite": "^6.2.2",
58
- "vitest": "^3.0.9"
54
+ "prettier": "^3.7.4",
55
+ "react": "^19.2.3",
56
+ "react-dom": "^19.2.3",
57
+ "typescript": "^5.9.3",
58
+ "typescript-eslint": "^8.49.0",
59
+ "vite": "^7.2.7",
60
+ "vitest": "^4.0.15"
59
61
  }
60
62
  }
package/src/highlight.ts CHANGED
@@ -2,13 +2,19 @@ import { Parser } from '@lezer/common'
2
2
  import { Language, LanguageDescription } from '@codemirror/language'
3
3
  import { Highlighter, highlightTree } from '@lezer/highlight'
4
4
  import { languages as builtinLanguages } from '@codemirror/language-data'
5
+ import { markdown } from '@codemirror/lang-markdown'
5
6
 
6
7
  export async function getCodeParser(
7
8
  languageName: string,
8
9
  fallbackLanguage?: Language,
9
10
  languages: LanguageDescription[] = builtinLanguages
10
11
  ): Promise<Parser | null> {
11
- if (languageName) {
12
+ if (languageName === 'markdown' || languageName === 'md') {
13
+ const mdSupport = markdown({
14
+ codeLanguages: builtinLanguages
15
+ })
16
+ return mdSupport.language.parser
17
+ } else {
12
18
  const found = LanguageDescription.matchLanguageName(
13
19
  languages,
14
20
  languageName,
@@ -67,6 +67,40 @@ describe('highlightCode', () => {
67
67
  })
68
68
  })
69
69
 
70
+ describe('Highlight codeblocks', () => {
71
+ it('highlights codeblocks in markdown', async () => {
72
+ const mdCode = '```js\nconst x = 123\n```'
73
+ const highlighted = await highlightCode(
74
+ 'markdown',
75
+ mdCode,
76
+ oneDarkHighlightStyle,
77
+ undefined,
78
+ undefined,
79
+ (text, style, from, to) => ({ text, style, from, to })
80
+ )
81
+ // Should have tokens for the markdown code block structure and the JS code inside
82
+ expect(highlighted.length).toBeGreaterThan(0)
83
+
84
+ // Find the code fence markers
85
+ const fenceStart = highlighted.find(t => t.text === '```')
86
+ expect(fenceStart).toBeDefined()
87
+
88
+ // Find the language info token
89
+ const langInfo = highlighted.find(t => t.text === 'js')
90
+ expect(langInfo).toBeDefined()
91
+
92
+ // Find the JS keyword 'const' inside the code block
93
+ const constToken = highlighted.find(t => t.text === 'const')
94
+ expect(constToken).toBeDefined()
95
+ expect(constToken?.style).not.toBeNull()
96
+
97
+ // Find the number '123'
98
+ const numberToken = highlighted.find(t => t.text === '123')
99
+ expect(numberToken).toBeDefined()
100
+ expect(numberToken?.style).not.toBeNull()
101
+ })
102
+ })
103
+
70
104
  describe('React Highlighter', () => {
71
105
  it('renders highlighted code', async () => {
72
106
  const code = 'const x = 123'
package/tsconfig.json CHANGED
@@ -3,17 +3,18 @@
3
3
  "compilerOptions": {
4
4
  "target": "esnext",
5
5
  "module": "esnext",
6
- "lib": ["es2024", "dom"],
6
+ "lib": ["esnext", "dom"],
7
7
  "jsx": "react-jsx",
8
8
  "esModuleInterop": true,
9
9
  "strict": true,
10
10
  "isolatedModules": true,
11
11
  "sourceMap": false,
12
- "moduleResolution": "node",
12
+ "moduleResolution": "bundler",
13
13
  "resolveJsonModule": true,
14
14
  "noImplicitAny": false,
15
15
  "outDir": "dist",
16
16
  "declaration": true,
17
- "declarationDir": "dist"
17
+ "declarationDir": "dist",
18
+ "skipLibCheck": true
18
19
  }
19
20
  }
package/vite.config.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="vitest" />
1
+ /// <reference types="vitest/config" />
2
2
  import { defineConfig } from 'vite'
3
3
  import react from '@vitejs/plugin-react'
4
4