Skip to content

Commit 96ee590

Browse files
refactor demo app syntax highlighter into separate module
1 parent 82563f5 commit 96ee590

File tree

2 files changed

+3
-31
lines changed

2 files changed

+3
-31
lines changed

demo/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Form from 'react-bootstrap/Form';
77
import Button from 'react-bootstrap/Button';
88
import ToastContainer from 'react-bootstrap/ToastContainer';
99
import Toast from 'react-bootstrap/Toast';
10-
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
10+
import SyntaxHighlighter from './SyntaxHighlighter';
1111
import Editor from './Editor';
1212
import { atomOneLight } from 'react-syntax-highlighter/dist/esm/styles/hljs';
1313
import { compareVersions } from 'compare-versions';

demo/src/Editor.tsx

+2-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
import { useRef, useState, useEffect, KeyboardEvent } from 'react';
22
import Form from 'react-bootstrap/Form';
3-
import {Light as SyntaxHighlighter} from 'react-syntax-highlighter';
3+
import SyntaxHighlighter from './SyntaxHighlighter';
44
import { atomOneLight } from 'react-syntax-highlighter/dist/esm/styles/hljs';
55

66
const TAB = " ";
77

8-
SyntaxHighlighter.registerLanguage('foo', (hljs: any) => ({
9-
case_insensitive: true, // language is case-insensitive
10-
keywords: {
11-
keyword: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
12-
literal: ['true', 'false', 'null'],
13-
},
14-
contains: [
15-
{
16-
className: 'attr',
17-
begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
18-
relevance: 1.01
19-
},
20-
{
21-
match: /[{}[\],:]/,
22-
className: "punctuation",
23-
relevance: 0
24-
},
25-
hljs.QUOTE_STRING_MODE,
26-
hljs.C_NUMBER_MODE,
27-
hljs.C_LINE_COMMENT_MODE,
28-
hljs.HASH_COMMENT_MODE,
29-
{
30-
className: 'meta',
31-
begin: '\/[^\\s]*',
32-
},
33-
],
34-
}));
35-
368
type EditorProps = {
379
className: string,
3810
id: string,
@@ -204,7 +176,7 @@ export default function Editor({ className, id, value, onChange }: EditorProps)
204176
}} ref={highlightRef}>
205177
<SyntaxHighlighter
206178
wrapLongLines={true}
207-
language="foo"
179+
language="elasticsearch"
208180
style={atomOneLight}
209181
customStyle={{
210182
margin: 0,

0 commit comments

Comments
 (0)