forked from matrix/element-web
Highlight ViewSource and Devtools ViewSource
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
843505f6a9
commit
8a7477f50c
|
@ -16,14 +16,17 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'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({
|
module.exports = React.createClass({
|
||||||
displayName: 'ViewSource',
|
displayName: 'ViewSource',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
content: React.PropTypes.object.isRequired,
|
content: PropTypes.object.isRequired,
|
||||||
onFinished: React.PropTypes.func.isRequired,
|
onFinished: PropTypes.func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
|
@ -45,9 +48,9 @@ module.exports = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<div className="mx_ViewSource">
|
<div className="mx_ViewSource">
|
||||||
<pre>
|
<Highlight className="json">
|
||||||
{JSON.stringify(this.props.content, null, 2)}
|
{ JSON.stringify(this.props.content, null, 2) }
|
||||||
</pre>
|
</Highlight>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import sdk from 'matrix-react-sdk';
|
import sdk from 'matrix-react-sdk';
|
||||||
|
import Highlight from '../elements/Highlight';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
|
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
|
||||||
|
|
||||||
|
@ -343,7 +344,9 @@ class RoomStateExplorer extends DevtoolsComponent {
|
||||||
|
|
||||||
return <div className="mx_ViewSource">
|
return <div className="mx_ViewSource">
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
<pre>{ JSON.stringify(this.state.event.event, null, 2) }</pre>
|
<Highlight className="json">
|
||||||
|
{ JSON.stringify(this.state.event.event, null, 2) }
|
||||||
|
</Highlight>
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_Dialog_buttons">
|
<div className="mx_Dialog_buttons">
|
||||||
<button onClick={this.onBack}>{ _t('Back') }</button>
|
<button onClick={this.onBack}>{ _t('Back') }</button>
|
||||||
|
@ -459,7 +462,9 @@ class AccountDataExplorer extends DevtoolsComponent {
|
||||||
|
|
||||||
return <div className="mx_ViewSource">
|
return <div className="mx_ViewSource">
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
<pre>{ JSON.stringify(this.state.event.event, null, 2) }</pre>
|
<Highlight className="json">
|
||||||
|
{ JSON.stringify(this.state.event.event, null, 2) }
|
||||||
|
</Highlight>
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_Dialog_buttons">
|
<div className="mx_Dialog_buttons">
|
||||||
<button onClick={this.onBack}>{ _t('Back') }</button>
|
<button onClick={this.onBack}>{ _t('Back') }</button>
|
||||||
|
|
|
@ -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 <pre className={`${className} mx_Highlight`} ref={this._ref}>
|
||||||
|
<code>{ children }</code>
|
||||||
|
</pre>;
|
||||||
|
}
|
||||||
|
}
|
|
@ -91,6 +91,7 @@
|
||||||
@import "./vector-web/views/dialogs/_SetEmailDialog.scss";
|
@import "./vector-web/views/dialogs/_SetEmailDialog.scss";
|
||||||
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
|
@import "./vector-web/views/dialogs/_SetPasswordDialog.scss";
|
||||||
@import "./vector-web/views/directory/_NetworkDropdown.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/_ImageView.scss";
|
||||||
@import "./vector-web/views/elements/_InlineSpinner.scss";
|
@import "./vector-web/views/elements/_InlineSpinner.scss";
|
||||||
@import "./vector-web/views/elements/_Spinner.scss";
|
@import "./vector-web/views/elements/_Spinner.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;
|
||||||
|
}
|
Loading…
Reference in New Issue