Skip to content

Commit fa3983e

Browse files
author
Aviad Lichtenstadt
committed
Change code wrapper to be a span and not div
1 parent 49c6404 commit fa3983e

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/index.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var Highlight = React.createClass({
1717
},
1818
highlightCode: function () {
1919
var domNode = ReactDOM.findDOMNode(this);
20-
var nodes = domNode.querySelectorAll('pre code');
20+
var nodes = domNode.querySelectorAll('span code');
2121
if (nodes.length > 0) {
2222
for (var i = 0; i < nodes.length; i=i+1) {
2323
hljs.highlightBlock(nodes[i]);
@@ -28,7 +28,7 @@ var Highlight = React.createClass({
2828
if (this.props.innerHTML) {
2929
return <div dangerouslySetInnerHTML={{__html: this.props.children}} className={this.props.className || null}></div>;
3030
} else {
31-
return <pre><code className={this.props.className}>{this.props.children}</code></pre>;
31+
return <span><code className={this.props.className}>{this.props.children}</code></span>;
3232
}
3333
}
3434
});

src/optimized.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var Highlight = React.createClass({
2525
hljs.registerLanguage(lang, require('highlight.js/lib/languages/' + lang));
2626
});
2727
var domNode = ReactDOM.findDOMNode(this);
28-
var nodes = domNode.querySelectorAll('pre code');
28+
var nodes = domNode.querySelectorAll('span code');
2929
if (nodes.length > 0) {
3030
for (var i = 0; i < nodes.length; i=i+1) {
3131
hljs.highlightBlock(nodes[i]);
@@ -36,7 +36,7 @@ var Highlight = React.createClass({
3636
if (this.props.innerHTML) {
3737
return <div dangerouslySetInnerHTML={{__html: this.props.children}} className={this.props.className || null}></div>;
3838
} else {
39-
return <pre><code className={this.props.className}>{this.props.children}</code></pre>;
39+
return <span><code className={this.props.className}>{this.props.children}</code></span>;
4040
}
4141
}
4242
});

test/highlight.test.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ describe('highlight', function() {
1515
var text = ReactDOMServer.renderToStaticMarkup(
1616
<Highlight>Some text</Highlight>
1717
);
18-
expect(text).toBe('<pre><code>Some text</code></pre>');
18+
expect(text).toBe('<span><code>Some text</code></span>');
1919
});
2020

2121
it('should assign className prop', function() {
2222
var text = ReactDOMServer.renderToStaticMarkup(
2323
<Highlight className='html'>Some text</Highlight>
2424
);
25-
expect(text).toBe('<pre><code class="html">Some text</code></pre>');
25+
expect(text).toBe('<span><code class="html">Some text</code></span>');
2626
});
2727

2828
it('should accept innerHTML prop', function() {

0 commit comments

Comments
 (0)