Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit e0b590b

Browse files
patched in jacobly's IE performance improvements from issue 102
1 parent 2af3a2e commit e0b590b

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h2>Setup</h2>
2727
<pre class="prettyprint">
2828
&lt;link href="prettify.css" type="text/css" rel="stylesheet" />
2929
&lt;script type="text/javascript" src="prettify.js">&lt;/script></pre>
30-
<li>Add <code class="prettyprint">onload="prettyPrint()"</code> to your
30+
<li>Add <code class="prettyprint lang-html">onload="prettyPrint()"</code> to your
3131
document's body tag.
3232
<li>Modify the stylesheet to get the coloring you prefer</li>
3333
</ol>

src/prettify.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,21 @@ window['_pr_isIE6'] = function () {
10771077
var trailingSpaceRe = /[ \r\n]$/;
10781078
var lastWasSpace = true; // the last text chunk emitted ended with a space.
10791079

1080+
// See bug 71 and http://stackoverflow.com/questions/136443/why-doesnt-ie7-
1081+
var isIE678 = window['_pr_isIE6']();
1082+
var lineBreakHtml = (
1083+
isIE678
1084+
? (job.sourceNode.tagName === 'PRE'
1085+
// Use line feeds instead of <br>s so that copying and pasting works
1086+
// on IE.
1087+
// Doing this on other browsers breaks lots of stuff since \r\n is
1088+
// treated as two newlines on Firefox.
1089+
? (isIE678 === 6 ? '&nbsp;\r\n' : '&nbsp;\r')
1090+
// IE collapses multiple adjacient <br>s into 1 line break.
1091+
// Prefix every newline with '&nbsp;' to prevent such behavior.
1092+
: '&nbsp;<br />')
1093+
: '<br />');
1094+
10801095
// A helper function that is responsible for opening sections of decoration
10811096
// and outputing properly escaped chunks of source
10821097
function emitTextUpTo(sourceIdx) {
@@ -1105,9 +1120,6 @@ window['_pr_isIE6'] = function () {
11051120
// Keep track of whether we need to escape space at the beginning of the
11061121
// next chunk.
11071122
lastWasSpace = trailingSpaceRe.test(htmlChunk);
1108-
// IE collapses multiple adjacient <br>s into 1 line break.
1109-
// Prefix every <br> with '&nbsp;' can prevent such IE's behavior.
1110-
var lineBreakHtml = window['_pr_isIE6']() ? '&nbsp;<br />' : '<br />';
11111123
html.push(htmlChunk.replace(newlineRe, lineBreakHtml));
11121124
outputIdx = sourceIdx;
11131125
}
@@ -1326,10 +1338,6 @@ window['_pr_isIE6'] = function () {
13261338
}
13271339

13281340
function prettyPrint(opt_whenDone) {
1329-
var isIE678 = window['_pr_isIE6']();
1330-
var ieNewline = isIE678 === 6 ? '\r\n' : '\r';
1331-
// See bug 71 and http://stackoverflow.com/questions/136443/why-doesnt-ie7-
1332-
13331341
// fetch a list of nodes to rewrite
13341342
var codeSegments = [
13351343
document.getElementsByTagName('pre'),
@@ -1434,20 +1442,6 @@ window['_pr_isIE6'] = function () {
14341442
cs.parentNode.replaceChild(pre, cs);
14351443
cs = pre;
14361444
}
1437-
1438-
// Replace <br>s with line-feeds so that copying and pasting works
1439-
// on IE 6.
1440-
// Doing this on other browsers breaks lots of stuff since \r\n is
1441-
// treated as two newlines on Firefox, and doing this also slows
1442-
// down rendering.
1443-
if (isIE678 && cs.tagName === 'PRE') {
1444-
var lineBreaks = cs.getElementsByTagName('br');
1445-
for (var j = lineBreaks.length; --j >= 0;) {
1446-
var lineBreak = lineBreaks[j];
1447-
lineBreak.parentNode.replaceChild(
1448-
document.createTextNode(ieNewline), lineBreak);
1449-
}
1450-
}
14511445
}
14521446

14531447
doWork();

0 commit comments

Comments
 (0)