From 8a7477f50cba19d98d901007b87561a52a181382 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 20 Dec 2017 20:40:41 +0000 Subject: [PATCH 1/5] Highlight ViewSource and Devtools ViewSource Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ViewSource.js | 15 +++--- .../views/dialogs/DevtoolsDialog.js | 9 +++- src/components/views/elements/Highlight.js | 51 +++++++++++++++++++ src/skins/vector/css/_components.scss | 1 + .../vector-web/views/elements/_Highlight.scss | 21 ++++++++ 5 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/components/views/elements/Highlight.js create mode 100644 src/skins/vector/css/vector-web/views/elements/_Highlight.scss diff --git a/src/components/structures/ViewSource.js b/src/components/structures/ViewSource.js index a0e198cec..8f60ae886 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 Highlight from '../views/elements/Highlight'; + 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 5d9168f5c..1b2af377c 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 Highlight from '../elements/Highlight'; 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/Highlight.js b/src/components/views/elements/Highlight.js new file mode 100644 index 000000000..1251264e3 --- /dev/null +++ b/src/components/views/elements/Highlight.js @@ -0,0 +1,51 @@ +/* +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. +*/ + +'use strict'; + +import React from 'react'; +import PropTypes from 'prop-types'; +import {highlightBlock} from 'highlight.js'; + +export default class Highlight extends React.Component { + static propTypes = { + className: PropTypes.string, + children: PropTypes.node, + }; + + constructor(props, context) { + super(props, context); + + this._ref = this._ref.bind(this); + } + + componentDidUpdate() { + if (this._el) highlightBlock(this._el); + } + + _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 0dd6a1b1b..c01a7dcf8 100644 --- a/src/skins/vector/css/_components.scss +++ b/src/skins/vector/css/_components.scss @@ -91,6 +91,7 @@ @import "./vector-web/views/dialogs/_SetEmailDialog.scss"; @import "./vector-web/views/dialogs/_SetPasswordDialog.scss"; @import "./vector-web/views/directory/_NetworkDropdown.scss"; +@import "./vector-web/views/elements/_Highlight.scss"; @import "./vector-web/views/elements/_ImageView.scss"; @import "./vector-web/views/elements/_InlineSpinner.scss"; @import "./vector-web/views/elements/_Spinner.scss"; diff --git a/src/skins/vector/css/vector-web/views/elements/_Highlight.scss b/src/skins/vector/css/vector-web/views/elements/_Highlight.scss new file mode 100644 index 000000000..9b35844ff --- /dev/null +++ b/src/skins/vector/css/vector-web/views/elements/_Highlight.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_Highlight { + /* inhibit hljs styling */ + background: none !important; + color: $light-fg-color !important; +} From 4386d45a972802d48d81d3016fdfd3a50a55ee87 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Tue, 16 Jan 2018 10:27:47 +0000 Subject: [PATCH 2/5] remove 'use strict' --- src/components/views/elements/Highlight.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/views/elements/Highlight.js b/src/components/views/elements/Highlight.js index 1251264e3..8706bb05a 100644 --- a/src/components/views/elements/Highlight.js +++ b/src/components/views/elements/Highlight.js @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -'use strict'; - import React from 'react'; import PropTypes from 'prop-types'; import {highlightBlock} from 'highlight.js'; From f5fc86258fc039c8f18e45cffb8770d0f827026a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 22 Jan 2018 18:59:18 +0000 Subject: [PATCH 3/5] s/Highlight/SyntaxHighlight/ Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ViewSource.js | 6 +++--- src/components/views/dialogs/DevtoolsDialog.js | 10 +++++----- .../elements/{Highlight.js => SyntaxHighlight.js} | 4 ++-- src/skins/vector/css/_components.scss | 2 +- .../{_Highlight.scss => _SyntaxHighlight.scss} | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename src/components/views/elements/{Highlight.js => SyntaxHighlight.js} (89%) rename src/skins/vector/css/vector-web/views/elements/{_Highlight.scss => _SyntaxHighlight.scss} (96%) diff --git a/src/components/structures/ViewSource.js b/src/components/structures/ViewSource.js index 8f60ae886..3a5d35a56 100644 --- a/src/components/structures/ViewSource.js +++ b/src/components/structures/ViewSource.js @@ -18,7 +18,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; -import Highlight from '../views/elements/Highlight'; +import SyntaxHighlight from '../views/elements/SyntaxHighlight'; module.exports = React.createClass({ @@ -48,9 +48,9 @@ module.exports = React.createClass({ render: function() { return (
- + { JSON.stringify(this.props.content, null, 2) } - +
); } diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index 1b2af377c..1d8f616c0 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -17,7 +17,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; import sdk from 'matrix-react-sdk'; -import Highlight from '../elements/Highlight'; +import SyntaxHighlight from '../elements/SyntaxHighlight'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; @@ -344,9 +344,9 @@ class RoomStateExplorer extends DevtoolsComponent { return
- + { JSON.stringify(this.state.event.event, null, 2) } - +
@@ -462,9 +462,9 @@ class AccountDataExplorer extends DevtoolsComponent { return
- + { JSON.stringify(this.state.event.event, null, 2) } - +
diff --git a/src/components/views/elements/Highlight.js b/src/components/views/elements/SyntaxHighlight.js similarity index 89% rename from src/components/views/elements/Highlight.js rename to src/components/views/elements/SyntaxHighlight.js index 8706bb05a..a7d8f894f 100644 --- a/src/components/views/elements/Highlight.js +++ b/src/components/views/elements/SyntaxHighlight.js @@ -18,7 +18,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import {highlightBlock} from 'highlight.js'; -export default class Highlight extends React.Component { +export default class SyntaxHighlight extends React.Component { static propTypes = { className: PropTypes.string, children: PropTypes.node, @@ -42,7 +42,7 @@ export default class Highlight extends React.Component { render() { const { className, children } = this.props; - return
+        return 
             { children }
         
; } diff --git a/src/skins/vector/css/_components.scss b/src/skins/vector/css/_components.scss index 8ac662700..a3783786c 100644 --- a/src/skins/vector/css/_components.scss +++ b/src/skins/vector/css/_components.scss @@ -93,7 +93,7 @@ @import "./vector-web/views/dialogs/_SetEmailDialog.scss"; @import "./vector-web/views/dialogs/_SetPasswordDialog.scss"; @import "./vector-web/views/directory/_NetworkDropdown.scss"; -@import "./vector-web/views/elements/_Highlight.scss"; +@import "./vector-web/views/elements/_SyntaxHighlight.scss"; @import "./vector-web/views/elements/_ImageView.scss"; @import "./vector-web/views/elements/_InlineSpinner.scss"; @import "./vector-web/views/elements/_Spinner.scss"; diff --git a/src/skins/vector/css/vector-web/views/elements/_Highlight.scss b/src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss similarity index 96% rename from src/skins/vector/css/vector-web/views/elements/_Highlight.scss rename to src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss index 9b35844ff..e97401a16 100644 --- a/src/skins/vector/css/vector-web/views/elements/_Highlight.scss +++ b/src/skins/vector/css/vector-web/views/elements/_SyntaxHighlight.scss @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -.mx_Highlight { +.mx_SyntaxHighlight { /* inhibit hljs styling */ background: none !important; color: $light-fg-color !important; From c2aa8137bb3cea61bdfa38c55d68704d7f43249e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 23 Jan 2018 20:02:47 +0000 Subject: [PATCH 4/5] sort components scss Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/skins/vector/css/_components.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skins/vector/css/_components.scss b/src/skins/vector/css/_components.scss index a3783786c..2319ebee8 100644 --- a/src/skins/vector/css/_components.scss +++ b/src/skins/vector/css/_components.scss @@ -93,10 +93,10 @@ @import "./vector-web/views/dialogs/_SetEmailDialog.scss"; @import "./vector-web/views/dialogs/_SetPasswordDialog.scss"; @import "./vector-web/views/directory/_NetworkDropdown.scss"; -@import "./vector-web/views/elements/_SyntaxHighlight.scss"; @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"; From 22b72985429ee79e882497b6f300879122f36d30 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 23 Jan 2018 20:28:39 +0000 Subject: [PATCH 5/5] add comments Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/elements/SyntaxHighlight.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/views/elements/SyntaxHighlight.js b/src/components/views/elements/SyntaxHighlight.js index a7d8f894f..82b5ae572 100644 --- a/src/components/views/elements/SyntaxHighlight.js +++ b/src/components/views/elements/SyntaxHighlight.js @@ -30,10 +30,14 @@ export default class SyntaxHighlight extends React.Component { 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();