diff --git a/src/components/structures/ViewSource.js b/src/components/structures/ViewSource.js index a0e198cecc..3a5d35a561 100644 --- a/src/components/structures/ViewSource.js +++ b/src/components/structures/ViewSource.js @@ -16,14 +16,17 @@ limitations under the License. 'use strict'; -var React = require('react'); +import React from 'react'; +import PropTypes from 'prop-types'; +import SyntaxHighlight from '../views/elements/SyntaxHighlight'; + module.exports = React.createClass({ displayName: 'ViewSource', propTypes: { - content: React.PropTypes.object.isRequired, - onFinished: React.PropTypes.func.isRequired, + content: PropTypes.object.isRequired, + onFinished: PropTypes.func.isRequired, }, componentDidMount: function() { @@ -45,9 +48,9 @@ module.exports = React.createClass({ render: function() { return (
-
-                    {JSON.stringify(this.props.content, null, 2)}
-                
+ + { JSON.stringify(this.props.content, null, 2) } +
); } diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index 5d9168f5c2..1d8f616c07 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -17,6 +17,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; import sdk from 'matrix-react-sdk'; +import SyntaxHighlight from '../elements/SyntaxHighlight'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; @@ -343,7 +344,9 @@ class RoomStateExplorer extends DevtoolsComponent { return
-
{ JSON.stringify(this.state.event.event, null, 2) }
+ + { JSON.stringify(this.state.event.event, null, 2) } +
@@ -459,7 +462,9 @@ class AccountDataExplorer extends DevtoolsComponent { return
-
{ JSON.stringify(this.state.event.event, null, 2) }
+ + { JSON.stringify(this.state.event.event, null, 2) } +
diff --git a/src/components/views/elements/SyntaxHighlight.js b/src/components/views/elements/SyntaxHighlight.js new file mode 100644 index 0000000000..82b5ae572c --- /dev/null +++ b/src/components/views/elements/SyntaxHighlight.js @@ -0,0 +1,53 @@ +/* +Copyright 2017 Michael Telatynski <7t3chguy@gmail.com> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React from 'react'; +import PropTypes from 'prop-types'; +import {highlightBlock} from 'highlight.js'; + +export default class SyntaxHighlight extends React.Component { + static propTypes = { + className: PropTypes.string, + children: PropTypes.node, + }; + + constructor(props, context) { + super(props, context); + + this._ref = this._ref.bind(this); + } + + // componentDidUpdate used here for reusability + // componentWillReceiveProps fires too early to call highlightBlock on. + componentDidUpdate() { + if (this._el) highlightBlock(this._el); + } + + // call componentDidUpdate because _ref is fired on initial render + // which does not fire componentDidUpdate + _ref(el) { + this._el = el; + this.componentDidUpdate(); + } + + render() { + const { className, children } = this.props; + + return
+            { children }
+        
; + } +} diff --git a/src/skins/vector/css/_components.scss b/src/skins/vector/css/_components.scss index c2725aeb9c..2319ebee84 100644 --- a/src/skins/vector/css/_components.scss +++ b/src/skins/vector/css/_components.scss @@ -96,6 +96,7 @@ @import "./vector-web/views/elements/_ImageView.scss"; @import "./vector-web/views/elements/_InlineSpinner.scss"; @import "./vector-web/views/elements/_Spinner.scss"; +@import "./vector-web/views/elements/_SyntaxHighlight.scss"; @import "./vector-web/views/globals/_MatrixToolbar.scss"; @import "./vector-web/views/messages/_DateSeparator.scss"; @import "./vector-web/views/messages/_MessageTimestamp.scss"; diff --git a/src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss b/src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss new file mode 100644 index 0000000000..e97401a160 --- /dev/null +++ b/src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss @@ -0,0 +1,21 @@ +/* +Copyright 2017 Michael Telatynski <7t3chguy@gmail.com> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +.mx_SyntaxHighlight { + /* inhibit hljs styling */ + background: none !important; + color: $light-fg-color !important; +}