Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4b0508a

Browse files
committed
Use correct highlight.js call
Previous call signature was deprecated. See highlightjs/highlight.js#2277 Signed-off-by: Clark Fischer <[email protected]>
1 parent de026c9 commit 4b0508a

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

src/components/views/elements/SyntaxHighlight.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2017 Michael Telatynski <[email protected]>
3+
Copyright 2023 The Matrix.org Foundation C.I.C.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -25,7 +26,7 @@ interface IProps {
2526
export default class SyntaxHighlight extends React.PureComponent<IProps> {
2627
public render(): JSX.Element {
2728
const { children: content, language } = this.props;
28-
const highlighted = language ? hljs.highlight(language, content) : hljs.highlightAuto(content);
29+
const highlighted = language ? hljs.highlight(content, { language }) : hljs.highlightAuto(content);
2930

3031
return (
3132
<pre className={`mx_SyntaxHighlight hljs language-${highlighted.language}`}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint @typescript-eslint/no-unused-vars: ["error", { "varsIgnorePattern": "^_" }] */
2+
/*
3+
Copyright 2023 The Matrix.org Foundation C.I.C.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import { render } from "@testing-library/react";
19+
import hljs, { type HighlightOptions } from "highlight.js";
20+
import React from "react";
21+
22+
import SyntaxHighlight from "../../../../src/components/views/elements/SyntaxHighlight";
23+
24+
describe("<SyntaxHighlight />", () => {
25+
it("renders", () => {
26+
const { container } = render(<SyntaxHighlight>console.log("Hello, World!");</SyntaxHighlight>);
27+
expect(container).toMatchSnapshot();
28+
});
29+
30+
it.each(["json", "javascript", "css"])("uses the provided language", (lang) => {
31+
const mock = jest.spyOn(hljs, "highlight");
32+
33+
render(<SyntaxHighlight language={lang}>// Hello, World</SyntaxHighlight>);
34+
35+
const [_lang, opts] = mock.mock.lastCall!;
36+
expect((opts as HighlightOptions)["language"]).toBe(lang);
37+
});
38+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<SyntaxHighlight /> renders 1`] = `
4+
<div>
5+
<pre
6+
class="mx_SyntaxHighlight hljs language-arcade"
7+
>
8+
<code>
9+
<span
10+
class="hljs-built_in"
11+
>
12+
console
13+
</span>
14+
.
15+
<span
16+
class="hljs-built_in"
17+
>
18+
log
19+
</span>
20+
(
21+
<span
22+
class="hljs-string"
23+
>
24+
"Hello, World!"
25+
</span>
26+
);
27+
</code>
28+
</pre>
29+
</div>
30+
`;

0 commit comments

Comments
 (0)