File tree 6 files changed +89
-17
lines changed
6 files changed +89
-17
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "rules": {
3
+ "no-extra-parens": 0,
4
+ "react/jsx-uses-vars": 1,
5
+ "global-strict": 1,
6
+ "quotes": [2, "single"],
7
+ "no-underscore-dangle": 0,
8
+ "space-infix-ops": 0,
9
+ "no-alert": 0
10
+ },
11
+ "ecmaFeatures": {
12
+ "jsx": true,
13
+ },
14
+ "env": {
15
+ "node": true,
16
+ "browser": true,
17
+ "es6": true,
18
+ "jasmine": true
19
+ },
20
+ "parser": "babel-eslint",
21
+ "plugins": [
22
+ "react"
23
+ ]
24
+ }
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ module.exports = function(config) {
14
14
15
15
// list of files / patterns to load in the browser
16
16
files : [
17
- 'node_modules/es5-shim/es5-shim.js' ,
18
- 'node_modules/react/dist/react-with-addons.js' ,
19
- 'test/**/*.jsx ' ,
17
+ 'node_modules/es5-shim/es5-shim.js' ,
18
+ 'node_modules/react/dist/react-with-addons.js' ,
19
+ 'test/**/*.js ' ,
20
20
] ,
21
21
22
22
@@ -27,17 +27,20 @@ module.exports = function(config) {
27
27
// preprocess matching files before serving them to the browser
28
28
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
29
29
preprocessors : {
30
- 'test/**/*.jsx ' : [ 'webpack' ]
30
+ 'test/**/*.js ' : [ 'webpack' ] ,
31
31
} ,
32
32
33
33
webpack : {
34
34
module : {
35
35
loaders : [
36
- { test : / \. ( j s | j s x ) $ / , loaders : [ 'babel' ] }
36
+ { test : / \. ( j s | j s x ) $ / , loaders : [ 'babel' ] } ,
37
37
]
38
38
} ,
39
39
externals : {
40
40
react : 'React'
41
+ } ,
42
+ resolve : {
43
+ root : __dirname
41
44
}
42
45
} ,
43
46
webpackServer : {
Original file line number Diff line number Diff line change 30
30
"autoprefixer-core" : " ^4.0.2" ,
31
31
"babel" : " ^5.6.14" ,
32
32
"babel-core" : " ^5.6.18" ,
33
+ "babel-eslint" : " ^6.0.2" ,
33
34
"babel-loader" : " ^5.3.1" ,
34
35
"es5-shim" : " ^4.1.7" ,
36
+ "eslint" : " ^2.8.0" ,
37
+ "eslint-plugin-react" : " ^4.3.0" ,
35
38
"gulp" : " ^3.8.10" ,
36
39
"gulp-ruby-sass" : " ^0.7.1" ,
37
40
"highlight.js" : " ^8.6.0" ,
38
41
"html-loader" : " ^0.2.3" ,
39
42
"jasmine-core" : " ^2.3.4" ,
40
43
"jsx-loader" : " ^0.12.2" ,
41
44
"karma" : " ^0.13.3" ,
45
+ "karma-jasmine" : " ^0.3.6" ,
46
+ "karma-phantomjs-launcher" : " ^0.2.1" ,
42
47
"karma-webpack" : " ^1.7.0" ,
43
48
"markdown-loader" : " ^0.1.2" ,
44
49
"multiline" : " ^1.0.1" ,
45
50
"node-libs-browser" : " ^0.5.2" ,
46
51
"phantomjs" : " ^1.9.17" ,
47
52
"raw-loader" : " ^0.5.1" ,
48
53
"react" : " ^0.14.0" ,
54
+ "react-addons-test-utils" : " ^0.14.3" ,
49
55
"webpack" : " ^1.12.2" ,
50
- "webpack-dev-server" : " ^1.6.6" ,
51
- "karma-jasmine" : " ^0.3.6" ,
52
- "karma-phantomjs-launcher" : " ^0.2.1" ,
53
- "react-addons-test-utils" : " ^0.14.3"
56
+ "webpack-dev-server" : " ^1.6.6"
54
57
},
55
58
"dependencies" : {
56
59
"highlight.js" : " ^8.4.x" ,
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ var Highlight = React.createClass({
6
6
getDefaultProps : function ( ) {
7
7
return {
8
8
innerHTML : false ,
9
- className : null
9
+ className : null ,
10
+ element : null ,
10
11
} ;
11
12
} ,
12
13
componentDidMount : function ( ) {
@@ -25,10 +26,24 @@ var Highlight = React.createClass({
25
26
}
26
27
} ,
27
28
render : function ( ) {
29
+ var Element = this . props . element ? React . DOM [ this . props . element ] : null ;
30
+
28
31
if ( this . props . innerHTML ) {
29
- return < div dangerouslySetInnerHTML = { { __html : this . props . children } } className = { this . props . className || null } > </ div > ;
32
+ if ( ! Element ) {
33
+ Element = React . DOM . div
34
+ }
35
+ return Element ( {
36
+ dangerouslySetInnerHTML : { __html : this . props . children } ,
37
+ className : this . props . className || null
38
+ } , null ) ;
30
39
} else {
31
- return < pre > < code className = { this . props . className } > { this . props . children } </ code > </ pre > ;
40
+ if ( Element ) {
41
+ return Element ( {
42
+ className :this . props . className
43
+ } , this . props . children ) ;
44
+ } else {
45
+ return < pre > < code className = { this . props . className } > { this . props . children } </ code > </ pre > ;
46
+ }
32
47
}
33
48
}
34
49
} ) ;
Original file line number Diff line number Diff line change @@ -33,10 +33,24 @@ var Highlight = React.createClass({
33
33
}
34
34
} ,
35
35
render : function ( ) {
36
+ var Element = this . props . element ? React . DOM [ this . props . element ] : null ;
37
+
36
38
if ( this . props . innerHTML ) {
37
- return < div dangerouslySetInnerHTML = { { __html : this . props . children } } className = { this . props . className || null } > </ div > ;
39
+ if ( ! Element ) {
40
+ Element = React . DOM . div
41
+ }
42
+ return Element ( {
43
+ dangerouslySetInnerHTML : { __html : this . props . children } ,
44
+ className : this . props . className || null
45
+ } , null ) ;
38
46
} else {
39
- return < pre > < code className = { this . props . className } > { this . props . children } </ code > </ pre > ;
47
+ if ( Element ) {
48
+ return Element ( {
49
+ className :this . props . className
50
+ } , this . props . children ) ;
51
+ } else {
52
+ return < pre > < code className = { this . props . className } > { this . props . children } </ code > </ pre > ;
53
+ }
40
54
}
41
55
}
42
56
} ) ;
Original file line number Diff line number Diff line change 1
- var Highlight = require ( '../' ) ;
1
+ var Highlight = require ( '../src ' ) ;
2
2
var ReactDOM = require ( 'react-dom' ) ;
3
3
var TestUtils = require ( 'react-addons-test-utils' ) ;
4
4
var ReactDOMServer = require ( 'react-dom/server' ) ;
@@ -25,14 +25,27 @@ describe('highlight', function() {
25
25
expect ( text ) . toBe ( '<pre><code class="html">Some text</code></pre>' ) ;
26
26
} ) ;
27
27
28
+ it ( 'should render children in span' , function ( ) {
29
+ var text = ReactDOMServer . renderToStaticMarkup (
30
+ < Highlight element = 'span' > Some text</ Highlight >
31
+ ) ;
32
+ expect ( text ) . toBe ( '<span>Some text</span>' ) ;
33
+ } ) ;
34
+
35
+ it ( 'should render innerHTML in span' , function ( ) {
36
+ var text = ReactDOMServer . renderToStaticMarkup (
37
+ < Highlight innerHTML = { true } element = 'span' > Some text</ Highlight >
38
+ ) ;
39
+ expect ( text ) . toBe ( '<span>Some text</span>' ) ;
40
+ } ) ;
41
+
28
42
it ( 'should accept innerHTML prop' , function ( ) {
29
43
var text = TestUtils . renderIntoDocument (
30
44
< Highlight innerHTML = { true } > { "<div>Sometext</div>" } </ Highlight >
31
45
) ;
32
46
expect ( ReactDOM . findDOMNode ( text ) . textContent ) . toBe ( 'Sometext' ) ;
33
47
} ) ;
34
48
35
- } ) ;
36
-
37
49
38
50
51
+ } ) ;
You can’t perform that action at this time.
0 commit comments