-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unify code highlight [WPB-12089] (#18526)
* feat: unity code highlight * refactor: create highlighCode utils * refactor(lexical-input): change color format for code theme
- Loading branch information
1 parent
7740526
commit 7fef0b1
Showing
9 changed files
with
325 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/script/components/RichTextEditor/plugins/CodeHighlightPlugin/CodeHighlightPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {useEffect} from 'react'; | ||
|
||
import {registerCodeHighlighting} from '@lexical/code'; | ||
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; | ||
|
||
export const CodeHighlightPlugin = (): null => { | ||
const [editor] = useLexicalComposerContext(); | ||
|
||
useEffect(() => { | ||
return registerCodeHighlighting(editor); | ||
}, [editor]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import Prism from 'prismjs'; | ||
import 'prismjs/components/prism-css'; | ||
import 'prismjs/components/prism-csv'; | ||
import 'prismjs/components/prism-haskell'; | ||
import 'prismjs/components/prism-java'; | ||
import 'prismjs/components/prism-javascript'; | ||
import 'prismjs/components/prism-json'; | ||
import 'prismjs/components/prism-kotlin'; | ||
import 'prismjs/components/prism-python'; | ||
import 'prismjs/components/prism-regex'; | ||
import 'prismjs/components/prism-ruby'; | ||
import 'prismjs/components/prism-typescript'; | ||
import 'prismjs/components/prism-yaml'; | ||
|
||
interface HighlightCodeParams { | ||
code: string; | ||
grammar: Prism.Grammar; | ||
lang: string; | ||
} | ||
|
||
export const highlightCode = ({code, grammar, lang}: HighlightCodeParams) => { | ||
// eslint-disable-next-line import/no-named-as-default-member | ||
return Prism.highlight(code, grammar, lang); | ||
}; | ||
|
||
// eslint-disable-next-line import/no-named-as-default-member | ||
export const languages = Prism.languages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.