mirror of https://github.com/istio/istio.io.git
Workaround bug in Firefox causing bad formatting in some code blocks. (#1379)
- Fixed syntax highlighting of code blocks with multiple commands. Each command is now run through the syntax highlighter separately, instead of mushing all commands into one go. The leading $ is also excluded which helps the highlighter. - Fixed the CSS source maps which couldn't be found due to a path problem. Running with Firefox alerted me to that. - Add missing JS source maps while I was there.
This commit is contained in:
parent
2eea4a83c0
commit
efce7c3a4e
18
Makefile
18
Makefile
|
@ -19,14 +19,16 @@ prep_build:
|
|||
npm install --prefix .tools/node uglify-js
|
||||
|
||||
build:
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_archive.scss static/css/light_theme_archive.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_normal.scss static/css/light_theme_normal.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_preliminary.scss static/css/light_theme_preliminary.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_archive.scss static/css/dark_theme_archive.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_normal.scss static/css/dark_theme_normal.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_preliminary.scss static/css/dark_theme_preliminary.css -s compressed
|
||||
.tools/node/node_modules/uglify-js/bin/uglifyjs src/js/misc.js src/js/prism.js --mangle --compress -o static/js/all.min.js
|
||||
.tools/node/node_modules/uglify-js/bin/uglifyjs src/js/styleSwitcher.js --mangle --compress -o static/js/styleSwitcher.min.js
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_archive.scss light_theme_archive.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_normal.scss light_theme_normal.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/light_theme_preliminary.scss light_theme_preliminary.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_archive.scss dark_theme_archive.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_normal.scss dark_theme_normal.css -s compressed
|
||||
.tools/node/node_modules/sass/sass.js src/sass/dark_theme_preliminary.scss dark_theme_preliminary.css -s compressed
|
||||
mv light_theme* static/css
|
||||
mv dark_theme* static/css
|
||||
.tools/node/node_modules/uglify-js/bin/uglifyjs src/js/misc.js src/js/prism.js --mangle --compress -o static/js/all.min.js --source-map
|
||||
.tools/node/node_modules/uglify-js/bin/uglifyjs src/js/styleSwitcher.js --mangle --compress -o static/js/styleSwitcher.min.js --source-map
|
||||
|
||||
##########
|
||||
|
||||
|
|
132
src/js/misc.js
132
src/js/misc.js
|
@ -114,21 +114,48 @@ function handleDOMLoaded() {
|
|||
// way.
|
||||
function patchDOM() {
|
||||
|
||||
var escapeChars = {
|
||||
'¢' : 'cent',
|
||||
'£' : 'pound',
|
||||
'¥' : 'yen',
|
||||
'€': 'euro',
|
||||
'©' :'copy',
|
||||
'®' : 'reg',
|
||||
'<' : 'lt',
|
||||
'>' : 'gt',
|
||||
'"' : 'quot',
|
||||
'&' : 'amp',
|
||||
'\'' : '#39'
|
||||
};
|
||||
|
||||
var regexString = '[';
|
||||
for(var key in escapeChars) {
|
||||
regexString += key;
|
||||
}
|
||||
regexString += ']';
|
||||
|
||||
var regex = new RegExp(regexString, 'g');
|
||||
|
||||
function escapeHTML(str) {
|
||||
return str.replace(regex, function(m) {
|
||||
return '&' + escapeChars[m] + ';';
|
||||
});
|
||||
}
|
||||
|
||||
// To compensate for https://github.com/gohugoio/hugo/issues/4785, certain code blocks are
|
||||
// indented in markdown by four spaces. This removes these four spaces so that the visuals
|
||||
// are correct.
|
||||
function compensateForHugoBug() {
|
||||
var code = document.getElementsByTagName('CODE');
|
||||
for (var i = 0; i < code.length; i++) {
|
||||
var text = code[i].innerText;
|
||||
var lines = text.split("\n");
|
||||
var lines = code[i].innerText.split("\n");
|
||||
if ((lines.length > 0) && lines[0].startsWith(" ")) {
|
||||
for (var j = 0; j < lines.length; j++) {
|
||||
if (lines[j].startsWith(" ")) {
|
||||
lines[j] = lines[j].slice(4);
|
||||
lines[j] = lines[j].substr(4);
|
||||
}
|
||||
}
|
||||
code[i].innerText = lines.join('\n');
|
||||
code[i].innerHTML = escapeHTML(lines.join('\n'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +176,6 @@ function handleDOMLoaded() {
|
|||
pre[i].parentElement.insertBefore(div, pre[i]);
|
||||
div.appendChild(pre[i]);
|
||||
div.appendChild(button);
|
||||
|
||||
// apply syntax highlighting
|
||||
Prism.highlightElement(pre[i].firstChild, false);
|
||||
}
|
||||
|
||||
var copyCode = new Clipboard('button.copy', {
|
||||
|
@ -217,62 +241,66 @@ function handleDOMLoaded() {
|
|||
}
|
||||
|
||||
if (cl !== "") {
|
||||
var text = code.innerText;
|
||||
var lines = text.split("\n");
|
||||
|
||||
var bottom = false;
|
||||
var bottomStart = 0;
|
||||
var lines = code.innerText.split("\n");
|
||||
var cmd = "";
|
||||
var output = "";
|
||||
var escape = false;
|
||||
var tmp = "";
|
||||
for (var j = 0; j < lines.length; j++) {
|
||||
var line = lines[j];
|
||||
|
||||
if (bottom) {
|
||||
output = output + "\n" + line;
|
||||
if (line.startsWith("$ ")) {
|
||||
if (tmp !== "") {
|
||||
cmd += "$ " + Prism.highlight(tmp, Prism.languages["bash"], "bash") + "\n";
|
||||
}
|
||||
|
||||
tmp = line.slice(2);
|
||||
} else if (escape) {
|
||||
// continuation
|
||||
tmp += "\n" + line;
|
||||
} else {
|
||||
if (line.startsWith("$ ")) {
|
||||
// line is definitely a command
|
||||
} else if (escape) {
|
||||
// continuation
|
||||
} else {
|
||||
bottom = true;
|
||||
output = line;
|
||||
continue;
|
||||
}
|
||||
|
||||
escape = (line.endsWith("\\"));
|
||||
|
||||
if (cmd !== "") {
|
||||
cmd = cmd + "\n";
|
||||
}
|
||||
cmd = cmd + line;
|
||||
}
|
||||
}
|
||||
|
||||
// in case someone forgot the $, treat everything as a command instead of as output
|
||||
if (cmd === "") {
|
||||
cmd = output;
|
||||
output = "";
|
||||
}
|
||||
|
||||
var colored = Prism.highlight(cmd, Prism.languages["bash"], "bash");
|
||||
var html = "<div class='command'>" + colored + "</div>";
|
||||
|
||||
if (output !== "") {
|
||||
// apply formatting to the output?
|
||||
var prefix = "language-command-output-as-";
|
||||
if (cl.length > prefix.length) {
|
||||
var lang = cl.substr(prefix.length);
|
||||
output = Prism.highlight(output, Prism.languages[lang], lang);
|
||||
bottomStart = j;
|
||||
break;
|
||||
}
|
||||
|
||||
html += "<div class='output'>" + output + "</div>";
|
||||
escape = line.endsWith("\\");
|
||||
}
|
||||
|
||||
code.innerHTML = html;
|
||||
code.classList.remove(cl);
|
||||
code.classList.add("command-output");
|
||||
if (tmp !== "") {
|
||||
cmd += "$ " + Prism.highlight(tmp, Prism.languages["bash"], "bash") + "\n";
|
||||
}
|
||||
|
||||
if (cmd !== "") {
|
||||
var html = "<div class='command'>" + cmd + "</div>";
|
||||
|
||||
var output = "";
|
||||
for (var j = bottomStart; j < lines.length; j++) {
|
||||
if (output !== "") {
|
||||
output += "\n";
|
||||
}
|
||||
output += lines[j];
|
||||
}
|
||||
|
||||
if (output !== "") {
|
||||
// apply formatting to the output?
|
||||
var prefix = "language-command-output-as-";
|
||||
if (cl.length > prefix.length) {
|
||||
var lang = cl.substr(prefix.length);
|
||||
output = Prism.highlight(output, Prism.languages[lang], lang);
|
||||
}
|
||||
|
||||
html += "<div class='output'>" + output + "</div>";
|
||||
}
|
||||
|
||||
code.innerHTML = html;
|
||||
code.classList.remove(cl);
|
||||
code.classList.add("command-output");
|
||||
} else {
|
||||
// someone probably forgot to start a block with $, so let's just treat the whole thing as being a `bash` block
|
||||
Prism.highlightElement(code, false);
|
||||
}
|
||||
} else {
|
||||
// this isn't one of our special code blocks, so handle normally
|
||||
Prism.highlightElement(code, false);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["src/js/styleSwitcher.js"],"names":["applyStyleSheet","title","i","a","document","getElementsByTagName","getAttribute","indexOf","disabled","item","getElementById","classList","add","remove","getPreferredStyleSheet","createCookie","name","value","days","date","Date","setTime","getTime","expires","toGMTString","cookie","readCookie","nameEQ","ca","split","length","c","charAt","substring","setActiveStyleSheet","loadActiveStyleSheet","window","onload","e"],"mappings":"AAAA,aAEA,SAASA,gBAAgBC,GACrB,IAAIC,EAAGC,EACP,IAAKD,EAAI,EAAIC,EAAIC,SAASC,qBAAqB,QAAQH,GAAKA,KACR,IAA5CC,EAAEG,aAAa,OAAOC,QAAQ,UAAmBJ,EAAEG,aAAa,WAChEH,EAAEK,SAAYL,EAAEG,aAAa,WAAaL,GAMlD,IAAIQ,EAAOL,SAASM,eAAe,oBACtB,OAATD,IACc,UAAVR,EACAQ,EAAKE,UAAUC,IAAI,UAEnBH,EAAKE,UAAUE,OAAO,WAKjB,QADbJ,EAAOL,SAASM,eAAe,sBAEb,SAAVT,EACAQ,EAAKE,UAAUC,IAAI,UAEnBH,EAAKE,UAAUE,OAAO,WAKlC,SAASC,yBACL,IAAIZ,EAAGC,EACP,IAAKD,EAAI,EAAIC,EAAIC,SAASC,qBAAqB,QAAQH,GAAKA,IACxD,IAAgD,IAA5CC,EAAEG,aAAa,OAAOC,QAAQ,WACe,IAA1CJ,EAAEG,aAAa,OAAOC,QAAQ,QAC9BJ,EAAEG,aAAa,SAClB,OAAOH,EAAEG,aAAa,SAG9B,OAAO,KAGX,SAASS,aAAaC,EAAMC,EAAOC,GAC/B,GAAIA,EAAM,CACN,IAAIC,EAAO,IAAIC,KAC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