chore(docs): Codeql fixes (#1793)

This commit is contained in:
Tony Brix 2020-11-06 08:34:31 -06:00 committed by GitHub
parent 320aeee27b
commit c50e39e58a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 21 deletions

View File

@ -72,7 +72,7 @@
</div>
</div>
<script>
var match = new RegExp('#/(.+)\.md(.*)', 'g').exec(window.location.hash);
var match = new RegExp('#/(.+)\\.md(.*)', 'g').exec(window.location.hash);
if (match && match[1]) {
// Redirect from URL format to new URL, for example:
// Old: https://marked.js.org/#/USING_PRO.md#renderer

View File

@ -322,15 +322,45 @@ function searchToObject() {
return obj;
}
function jsonString(input) {
var output = (input + '')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t')
.replace(/\f/g, '\\f')
.replace(/[\\"']/g, '\\$&')
.replace(/\u0000/g, '\\0');
return '"' + output + '"';
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
}
function stringRepeat(char, times) {
var s = '';
for (var i = 0; i < times; i++) {
s += char;
}
return s;
}
function jsonString(input, level) {
level = level || 0;
if (isArray(input)) {
if (input.length === 0) {
return '[]';
}
var items = [],
i;
if (!isArray(input[0]) && typeof input[0] === 'object' && input[0] !== null) {
for (i = 0; i < input.length; i++) {
items.push(stringRepeat(' ', 2 * level) + jsonString(input[i], level + 1));
}
return '[\n' + items.join('\n') + '\n]';
}
for (i = 0; i < input.length; i++) {
items.push(jsonString(input[i], level));
}
return '[' + items.join(', ') + ']';
} else if (typeof input === 'object' && input !== null) {
var props = [];
for (var prop in input) {
props.push(prop + ':' + jsonString(input[prop], level));
}
return '{' + props.join(', ') + '}';
} else {
return JSON.stringify(input);
}
}
function getScrollSize() {
@ -422,19 +452,16 @@ function checkForChanges() {
} else {
var startTime = new Date();
var lexed = marked.lexer(markdown, options);
var lexedList = [];
for (var i = 0; i < lexed.length; i++) {
var lexedLine = [];
for (var j in lexed[i]) {
lexedLine.push(j + ':' + jsonString(lexed[i][j]));
}
lexedList.push('{' + lexedLine.join(', ') + '}');
}
var lexedList = jsonString(lexed);
var parsed = marked.parser(lexed, options);
var scrollPercent = getScrollPercent();
setParsed(parsed, lexedList.join('\n'));
setScrollPercent(scrollPercent);
var endTime = new Date();
$previewElem.classList.remove('error');
$htmlElem.classList.remove('error');
$lexerElem.classList.remove('error');
var scrollPercent = getScrollPercent();
setParsed(parsed, lexedList);
setScrollPercent(scrollPercent);
delayTime = endTime - startTime;
setResponseTime(delayTime);
if (delayTime < 50) {