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

Commit ad95566

Browse files
issue 71: copy and paste in IE 6, 7, and 8
1 parent a5b4d3c commit ad95566

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/prettify.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ window['PR_normalizedHtml']
9090
*/
9191
= window['prettyPrint'] = void 0;
9292

93-
/** browser detection. @extern */
93+
/** browser detection. @extern @returns false if not IE, otherwise the major version. */
9494
window['_pr_isIE6'] = function () {
95-
var isIE6 = navigator && navigator.userAgent &&
96-
/\bMSIE 6\./.test(navigator.userAgent);
97-
window['_pr_isIE6'] = function () { return isIE6; };
98-
return isIE6;
95+
var ieVersion = navigator && navigator.userAgent &&
96+
navigator.userAgent.match(/\bMSIE ([678])\./);
97+
ieVersion = ieVersion ? +ieVersion[1] : false;
98+
window['_pr_isIE6'] = function () { return ieVersion; };
99+
return ieVersion;
99100
};
100101

101102

@@ -1319,7 +1320,9 @@ window['_pr_isIE6'] = function () {
13191320
}
13201321

13211322
function prettyPrint(opt_whenDone) {
1322-
var isIE6 = window['_pr_isIE6']();
1323+
var isIE678 = window['_pr_isIE6']();
1324+
var ieNewline = isIE678 === 6 ? '\r\n' : '\r';
1325+
// See bug 71 and http://stackoverflow.com/questions/136443/why-doesnt-ie7-
13231326

13241327
// fetch a list of nodes to rewrite
13251328
var codeSegments = [
@@ -1431,12 +1434,12 @@ window['_pr_isIE6'] = function () {
14311434
// Doing this on other browsers breaks lots of stuff since \r\n is
14321435
// treated as two newlines on Firefox, and doing this also slows
14331436
// down rendering.
1434-
if (isIE6 && cs.tagName === 'PRE') {
1437+
if (isIE678 && cs.tagName === 'PRE') {
14351438
var lineBreaks = cs.getElementsByTagName('br');
14361439
for (var j = lineBreaks.length; --j >= 0;) {
14371440
var lineBreak = lineBreaks[j];
14381441
lineBreak.parentNode.replaceChild(
1439-
document.createTextNode('\r'), lineBreak);
1442+
document.createTextNode(ieNewline), lineBreak);
14401443
}
14411444
}
14421445
}

tests/prettify_test.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,9 @@ <h1>Bug 21 - code doesn't copy and paste well in IE</h1>
729729
&lt;title&gt;Test&lt;/title&gt;
730730
&lt;/head&gt;
731731
&lt;/html&gt;</pre>
732-
<p>To test this bug, disable overriding of _pr_isIE6 above, and copy and paste
733-
the above into Notepad.</p>
732+
<p>To test this bug, disable overriding of _pr_isIE6 in test_base.js
733+
by putting #testcopypaste on the end of the URL and reloading the
734+
page, then copy and paste the above into Notepad.</p>
734735

735736
<h1>Bug 22 - Line numbers and other non-code spans in code</h1>
736737
<pre class="prettyprint" id="issue22"

0 commit comments

Comments
 (0)