File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828 "filesize" : " ^3.1.2" ,
2929 "flux" : " ~2.0.3" ,
3030 "gfm.css" : " ^1.1.1" ,
31+ "highlight.js" : " ^8.9.1" ,
3132 "linkifyjs" : " ^2.0.0-beta.4" ,
3233 "matrix-js-sdk" : " https://github.com/matrix-org/matrix-js-sdk.git#develop" ,
3334 "matrix-react-sdk" : " https://github.com/matrix-org/matrix-react-sdk.git#develop" ,
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ limitations under the License.
1818
1919var React = require ( 'react' ) ;
2020var sanitizeHtml = require ( 'sanitize-html' ) ;
21+ var highlight = require ( 'highlight.js' ) ;
2122
2223var sanitizeHtmlParams = {
2324 allowedTags : [
@@ -94,6 +95,14 @@ module.exports = {
9495 }
9596
9697 return body ;
97- }
98+ } ,
99+
100+ highlightDom : function ( element ) {
101+ var blocks = element . getElementsByTagName ( "code" ) ;
102+ for ( var i = 0 ; i < blocks . length ; i ++ ) {
103+ highlight . highlightBlock ( blocks [ i ] ) ;
104+ }
105+ } ,
106+
98107}
99108
Original file line number Diff line number Diff line change 1+ . . / . . / . . / . . / node_modules/ matrix- react- sdk/ node_modules/ highlight. js / styles/ github. css
Original file line number Diff line number Diff line change @@ -25,6 +25,20 @@ module.exports = React.createClass({
2525 displayName : 'MNoticeTile' ,
2626 mixins : [ MNoticeTileController ] ,
2727
28+ componentDidMount : function ( ) {
29+ HtmlUtils . highlightDom ( this . getDOMNode ( ) ) ;
30+ } ,
31+
32+ componentDidUpdate : function ( ) {
33+ HtmlUtils . highlightDom ( this . getDOMNode ( ) ) ;
34+ } ,
35+
36+ shouldComponentUpdate : function ( nextProps ) {
37+ // exploit that events are immutable :)
38+ return ( nextProps . mxEvent . getId ( ) !== this . props . mxEvent . getId ( ) ||
39+ nextProps . searchTerm !== this . props . searchTerm ) ;
40+ } ,
41+
2842 // XXX: fix horrible duplication with MTextTile
2943 render : function ( ) {
3044 var content = this . props . mxEvent . getContent ( ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,20 @@ module.exports = React.createClass({
2525 displayName : 'MTextTile' ,
2626 mixins : [ MTextTileController ] ,
2727
28+ componentDidMount : function ( ) {
29+ HtmlUtils . highlightDom ( this . getDOMNode ( ) ) ;
30+ } ,
31+
32+ componentDidUpdate : function ( ) {
33+ HtmlUtils . highlightDom ( this . getDOMNode ( ) ) ;
34+ } ,
35+
36+ shouldComponentUpdate : function ( nextProps ) {
37+ // exploit that events are immutable :)
38+ return ( nextProps . mxEvent . getId ( ) !== this . props . mxEvent . getId ( ) ||
39+ nextProps . searchTerm !== this . props . searchTerm ) ;
40+ } ,
41+
2842 render : function ( ) {
2943 var content = this . props . mxEvent . getContent ( ) ;
3044 var body = HtmlUtils . bodyToHtml ( content , this . props . searchTerm ) ;
You can’t perform that action at this time.
0 commit comments