Skip to content

Commit 670f02a

Browse files
committed
Merge branches 'develop' and 't3chguy/highlight_things' of github.com:vector-im/riot-web into t3chguy/highlight_things
2 parents a94208e + 4386d45 commit 670f02a

5 files changed

Lines changed: 87 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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
import React from 'react';
18+
import PropTypes from 'prop-types';
19+
import {highlightBlock} from 'highlight.js';
20+
21+
export default class Highlight extends React.Component {
22+
static propTypes = {
23+
className: PropTypes.string,
24+
children: PropTypes.node,
25+
};
26+
27+
constructor(props, context) {
28+
super(props, context);
29+
30+
this._ref = this._ref.bind(this);
31+
}
32+
33+
componentDidUpdate() {
34+
if (this._el) highlightBlock(this._el);
35+
}
36+
37+
_ref(el) {
38+
this._el = el;
39+
this.componentDidUpdate();
40+
}
41+
42+
render() {
43+
const { className, children } = this.props;
44+
45+
return <pre className={`${className} mx_Highlight`} ref={this._ref}>
46+
<code>{ children }</code>
47+
</pre>;
48+
}
49+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
@import "./vector-web/views/dialogs/_SetEmailDialog.scss";
9494
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
9595
@import "./vector-web/views/directory/_NetworkDropdown.scss";
96+
@import "./vector-web/views/elements/_Highlight.scss";
9697
@import "./vector-web/views/elements/_ImageView.scss";
9798
@import "./vector-web/views/elements/_InlineSpinner.scss";
9899
@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)