Skip to content

Commit

Permalink
Don't count on globally available 'navigator'
Browse files Browse the repository at this point in the history
  • Loading branch information
isagalaev committed Jun 14, 2012
1 parent 26c9861 commit 9c492df
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function() {
}
}

var is_old_IE = (typeof navigator !== 'undefined' && /MSIE [678]/.test(navigator.userAgent));

function blockText(block, ignoreNewLines) {
var result = '';
for (var i = 0; i < block.childNodes.length; i++)
Expand All @@ -40,8 +42,7 @@ function() {
result += '\n';
else
result += blockText(block.childNodes[i]);
// Thank you, MSIE...
if (/MSIE [678]/.test(navigator.userAgent))
if (is_old_IE)
result = result.replace(/\r/g, '\n');
return result;
}
Expand Down Expand Up @@ -531,7 +532,7 @@ function() {
if (!class_name.match('(\\s|^)(language-)?' + language + '(\\s|$)')) {
class_name = class_name ? (class_name + ' ' + language) : language;
}
if (/MSIE [678]/.test(navigator.userAgent) && block.tagName == 'CODE' && block.parentNode.tagName == 'PRE') {
if (is_old_IE && block.tagName == 'CODE' && block.parentNode.tagName == 'PRE') {
// This is for backwards compatibility only. IE needs this strange
// hack becasue it cannot just cleanly replace <code> block contents.
pre = block.parentNode;
Expand Down

0 comments on commit 9c492df

Please sign in to comment.