File tree Expand file tree Collapse file tree 6 files changed +89
-17
lines changed Expand file tree Collapse file tree 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) {
1414
1515 // list of files / patterns to load in the browser
1616 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 ' ,
2020 ] ,
2121
2222
@@ -27,17 +27,20 @@ module.exports = function(config) {
2727 // preprocess matching files before serving them to the browser
2828 // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
2929 preprocessors : {
30- 'test/**/*.jsx ' : [ 'webpack' ]
30+ 'test/**/*.js ' : [ 'webpack' ] ,
3131 } ,
3232
3333 webpack : {
3434 module : {
3535 loaders : [
36- { test : / \. ( j s | j s x ) $ / , loaders : [ 'babel' ] }
36+ { test : / \. ( j s | j s x ) $ / , loaders : [ 'babel' ] } ,
3737 ]
3838 } ,
3939 externals : {
4040 react : 'React'
41+ } ,
42+ resolve : {
43+ root : __dirname
4144 }
4245 } ,
4346 webpackServer : {
Original file line number Diff line number Diff line change 3030 "autoprefixer-core" : " ^4.0.2" ,
3131 "babel" : " ^5.6.14" ,
3232 "babel-core" : " ^5.6.18" ,
33+ "babel-eslint" : " ^6.0.2" ,
3334 "babel-loader" : " ^5.3.1" ,
3435 "es5-shim" : " ^4.1.7" ,
36+ "eslint" : " ^2.8.0" ,
37+ "eslint-plugin-react" : " ^4.3.0" ,
3538 "gulp" : " ^3.8.10" ,
3639 "gulp-ruby-sass" : " ^0.7.1" ,
3740 "highlight.js" : " ^8.6.0" ,
3841 "html-loader" : " ^0.2.3" ,
3942 "jasmine-core" : " ^2.3.4" ,
4043 "jsx-loader" : " ^0.12.2" ,
4144 "karma" : " ^0.13.3" ,
45+ "karma-jasmine" : " ^0.3.6" ,
46+ "karma-phantomjs-launcher" : " ^0.2.1" ,
4247 "karma-webpack" : " ^1.7.0" ,
4348 "markdown-loader" : " ^0.1.2" ,
4449 "multiline" : " ^1.0.1" ,
4550 "node-libs-browser" : " ^0.5.2" ,
4651 "phantomjs" : " ^1.9.17" ,
4752 "raw-loader" : " ^0.5.1" ,
4853 "react" : " ^0.14.0" ,
54+ "react-addons-test-utils" : " ^0.14.3" ,
4955 "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"
5457 },
5558 "dependencies" : {
5659 "highlight.js" : " ^8.4.x" ,
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ var Highlight = React.createClass({
66 getDefaultProps : function ( ) {
77 return {
88 innerHTML : false ,
9- className : null
9+ className : null ,
10+ element : null ,
1011 } ;
1112 } ,
1213 componentDidMount : function ( ) {
@@ -25,10 +26,24 @@ var Highlight = React.createClass({
2526 }
2627 } ,
2728 render : function ( ) {
29+ var Element = this . props . element ? React . DOM [ this . props . element ] : null ;
30+
2831 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 ) ;
3039 } 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+ }
3247 }
3348 }
3449} ) ;
Original file line number Diff line number Diff line change @@ -33,10 +33,24 @@ var Highlight = React.createClass({
3333 }
3434 } ,
3535 render : function ( ) {
36+ var Element = this . props . element ? React . DOM [ this . props . element ] : null ;
37+
3638 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 ) ;
3846 } 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+ }
4054 }
4155 }
4256} ) ;
Original file line number Diff line number Diff line change 1- var Highlight = require ( '../' ) ;
1+ var Highlight = require ( '../src ' ) ;
22var ReactDOM = require ( 'react-dom' ) ;
33var TestUtils = require ( 'react-addons-test-utils' ) ;
44var ReactDOMServer = require ( 'react-dom/server' ) ;
@@ -25,14 +25,27 @@ describe('highlight', function() {
2525 expect ( text ) . toBe ( '<pre><code class="html">Some text</code></pre>' ) ;
2626 } ) ;
2727
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+
2842 it ( 'should accept innerHTML prop' , function ( ) {
2943 var text = TestUtils . renderIntoDocument (
3044 < Highlight innerHTML = { true } > { "<div>Sometext</div>" } </ Highlight >
3145 ) ;
3246 expect ( ReactDOM . findDOMNode ( text ) . textContent ) . toBe ( 'Sometext' ) ;
3347 } ) ;
3448
35- } ) ;
36-
3749
3850
51+ } ) ;
You can’t perform that action at this time.
0 commit comments