Skip to content

Commit 8a7477f

Browse files
committed
Highlight ViewSource and Devtools ViewSource
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 843505f commit 8a7477f

5 files changed

Lines changed: 89 additions & 8 deletions

File tree

‎src/components/structures/ViewSource.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ limitations under the License.
1616

1717
'use strict';
1818

19-
var React = require('react');
19+
import React from 'react';
20+
import PropTypes from 'prop-types';
21+
import Highlight from '../views/elements/Highlight';
22+
2023

2124
module.exports = React.createClass({
2225
displayName: 'ViewSource',
2326

2427
propTypes: {
25-
content: React.PropTypes.object.isRequired,
26-
onFinished: React.PropTypes.func.isRequired,
28+
content: PropTypes.object.isRequired,
29+
onFinished: PropTypes.func.isRequired,
2730
},
2831

2932
componentDidMount: function() {
@@ -45,9 +48,9 @@ module.exports = React.createClass({
4548
render: function() {
4649
return (
4750
<div className="mx_ViewSource">
48-
<pre>
49-
{JSON.stringify(this.props.content, null, 2)}
50-
</pre>
51+
<Highlight className="json">
52+
{ JSON.stringify(this.props.content, null, 2) }
53+
</Highlight>
5154
</div>
5255
);
5356
}

‎src/components/views/dialogs/DevtoolsDialog.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
import React from 'react';
1818
import PropTypes from 'prop-types';
1919
import sdk from 'matrix-react-sdk';
20+
import Highlight from '../elements/Highlight';
2021
import { _t } from 'matrix-react-sdk/lib/languageHandler';
2122
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
2223

@@ -343,7 +344,9 @@ class RoomStateExplorer extends DevtoolsComponent {
343344

344345
return <div className="mx_ViewSource">
345346
<div className="mx_Dialog_content">
346-
<pre>{ JSON.stringify(this.state.event.event, null, 2) }</pre>
347+
<Highlight className="json">
348+
{ JSON.stringify(this.state.event.event, null, 2) }
349+
</Highlight>
347350
</div>
348351
<div className="mx_Dialog_buttons">
349352
<button onClick={this.onBack}>{ _t('Back') }</button>
@@ -459,7 +462,9 @@ class AccountDataExplorer extends DevtoolsComponent {
459462

460463
return <div className="mx_ViewSource">
461464
<div className="mx_Dialog_content">
462-
<pre>{ JSON.stringify(this.state.event.event, null, 2) }</pre>
465+
<Highlight className="json">
466+
{ JSON.stringify(this.state.event.event, null, 2) }
467+
</Highlight>
463468
</div>
464469
<div className="mx_Dialog_buttons">
465470
<button onClick={this.onBack}>{ _t('Back') }</button>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2017 Michael Telatynski <7t3chguy@gmail.com>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
import React from 'react';
20+
import PropTypes from 'prop-types';
21+
import {highlightBlock} from 'highlight.js';
22+
23+
export default class Highlight extends React.Component {
24+
static propTypes = {
25+
className: PropTypes.string,
26+
children: PropTypes.node,
27+
};
28+
29+
constructor(props, context) {
30+
super(props, context);
31+
32+
this._ref = this._ref.bind(this);
33+
}
34+
35+
componentDidUpdate() {
36+
if (this._el) highlightBlock(this._el);
37+
}
38+
39+
_ref(el) {
40+
this._el = el;
41+
this.componentDidUpdate();
42+
}
43+
44+
render() {
45+
const { className, children } = this.props;
46+
47+
return <pre className={`${className} mx_Highlight`} ref={this._ref}>
48+
<code>{ children }</code>
49+
</pre>;
50+
}
51+
}

‎src/skins/vector/css/_components.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
@import "./vector-web/views/dialogs/_SetEmailDialog.scss";
9292
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
9393
@import "./vector-web/views/directory/_NetworkDropdown.scss";
94+
@import "./vector-web/views/elements/_Highlight.scss";
9495
@import "./vector-web/views/elements/_ImageView.scss";
9596
@import "./vector-web/views/elements/_InlineSpinner.scss";
9697
@import "./vector-web/views/elements/_Spinner.scss";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2017 Michael Telatynski <7t3chguy@gmail.com>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_Highlight {
18+
/* inhibit hljs styling */
19+
background: none !important;
20+
color: $light-fg-color !important;
21+
}

0 commit comments

Comments
 (0)