summaryrefslogtreecommitdiff
path: root/doc/_static
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-26 10:59:28 +0100
committerMartin Fischer <martin@push-f.com>2021-12-26 21:18:12 +0100
commitede57434efc733cd396e64872cde7af81cb7639f (patch)
treebc8a2a84435bb710b6fb5d5603fbe9b989083ca2 /doc/_static
parent2c457f00645cea1f8ef467dca7b98c2268879cf0 (diff)
downloadpygments-git-ede57434efc733cd396e64872cde7af81cb7639f.tar.gz
demo: disable copy link when URI too long for web server
Diffstat (limited to 'doc/_static')
-rw-r--r--doc/_static/demo.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/doc/_static/demo.js b/doc/_static/demo.js
index 936bd501..8124cccd 100644
--- a/doc/_static/demo.js
+++ b/doc/_static/demo.js
@@ -74,16 +74,28 @@ async function highlight() {
var style = document.getElementById("style").value;
var file = document.getElementById("file").files[0];
+
+ const uriTooLongMsg = document.getElementById('uri-too-long');
+
let code;
if (file) {
code = await file.arrayBuffer();
copyLink.hidden = true;
+ uriTooLongMsg.hidden = true;
} else {
code = document.getElementById("code").value;
- var link = document.location.origin + document.location.pathname +
+ var url = document.location.origin + document.location.pathname +
"?lexer=" + encodeURIComponent(lexer) + "&code=" + encodeURIComponent(code);
- copyLink.href = link;
- copyLink.hidden = false;
+ if (url.length > 8201) {
+ // pygments.org is hosted on GitHub pages which does not support URIs longer than 8201
+ copyLink.hidden = true;
+ uriTooLongMsg.hidden = false;
+ } else {
+ copyLink.href = url;
+ copyLink.textContent = 'Copy link';
+ copyLink.hidden = false;
+ uriTooLongMsg.hidden = true;
+ }
}
highlightWorker.postMessage({code, lexer, style});