summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/_static/demo.js18
-rw-r--r--doc/_templates/demo.html1
2 files changed, 16 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});
diff --git a/doc/_templates/demo.html b/doc/_templates/demo.html
index 16163e6f..648b24a2 100644
--- a/doc/_templates/demo.html
+++ b/doc/_templates/demo.html
@@ -54,6 +54,7 @@
<input type="button" value="Download" onclick="download_code()">
&nbsp;&nbsp;&nbsp;
<a id="copylink" role="button">Copy link</a>
+ <span hidden id="uri-too-long">(Copy link unavailable because code too long)</span>
</div>
<script type="text/javascript" src="{{ pathto("_static/demo.js", 1) }}"></script>
{% endblock %}