Skip to content

Commit 43d02a3

Browse files
committed
Rewrites long lines
1 parent a5652cd commit 43d02a3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

htmlpreview.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
* NOTE: This is function 2 of 2 that is git-forge specific.
2525
*/
2626
const isGitForgeFileUrl = function (url) {
27-
return (url.indexOf('//raw.githubusercontent.com') > 0 || url.indexOf('//bitbucket.org') > 0);
27+
return (url.indexOf('//raw.githubusercontent.com') > 0
28+
|| url.indexOf('//bitbucket.org') > 0);
2829
}
2930

3031
/**
@@ -136,7 +137,9 @@
136137
}
137138
});
138139
// Scripts
139-
const script = document.querySelectorAll('script[type="text/htmlpreview"]');
140+
const script = document.querySelectorAll(
141+
'script[type="text/htmlpreview"]'
142+
);
140143
for (i = 0; i < script.length; ++i) {
141144
// Get absolute URL
142145
src = script[i].src;
@@ -154,7 +157,10 @@
154157
loadJS(res[i]);
155158
}
156159
// Dispatch DOMContentLoaded event after loading all scripts
157-
document.dispatchEvent(new Event('DOMContentLoaded', {bubbles: true, cancelable: true}));
160+
document.dispatchEvent(new Event(
161+
'DOMContentLoaded',
162+
{bubbles: true, cancelable: true}
163+
));
158164
});
159165
};
160166

@@ -163,9 +169,13 @@
163169
// Add <base> just after <head>
164170
// and replace <script type="text/javascript">
165171
// with <script type="text/htmlpreview">
166-
data = data
167-
.replace(/<head([^>]*)>/i, '<head$1><base href="' + rawFileUrl + '">')
168-
.replace(/<script(\s*src=["'][^"']*["'])?(\s*type=["'](text|application)\/javascript["'])?/gi, '<script type="text/htmlpreview"$1');
172+
data = data.replace(
173+
/<head([^>]*)>/i,
174+
'<head$1><base href="' + rawFileUrl + '">'
175+
).replace(
176+
/<script(\s*src=["'][^"']*["'])?(\s*type=["'](text|application)\/javascript["'])?/gi,
177+
'<script type="text/htmlpreview"$1'
178+
);
169179
// Delay updating document to have it cleared before
170180
setTimeout(function () {
171181
document.open();
@@ -199,7 +209,8 @@
199209
];
200210
return fetch(proxy[i] + url, options).then(function (res) {
201211
if (!res.ok) {
202-
throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText);
212+
const errMsg = res.status + ' ' + res.statusText;
213+
throw new Error('Cannot load ' + url + ': ' + errMsg);
203214
}
204215
return res.text();
205216
}).catch(function (error) {

0 commit comments

Comments
 (0)