Commit 3f4ae00dc04e5ff84ed3d73bc59af74699862982

dreammaster82 2020-11-24T19:41:10

File Highlight: Fixed IE compatibility problem (#2656) The File Highlight plugin used the `Element#matches` which isn't supported by IE11, so a small polyfill was added.

diff --git a/plugins/file-highlight/prism-file-highlight.js b/plugins/file-highlight/prism-file-highlight.js
index 93db3ac..60ca500 100644
--- a/plugins/file-highlight/prism-file-highlight.js
+++ b/plugins/file-highlight/prism-file-highlight.js
@@ -3,6 +3,11 @@
 		return;
 	}
 
+	// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
+	if (!Element.prototype.matches) {
+		Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
+	}
+
 	var Prism = window.Prism;
 
 	var LOADING_MESSAGE = 'Loading…';
diff --git a/plugins/file-highlight/prism-file-highlight.min.js b/plugins/file-highlight/prism-file-highlight.min.js
index 843072d..d33e2de 100644
--- a/plugins/file-highlight/prism-file-highlight.min.js
+++ b/plugins/file-highlight/prism-file-highlight.min.js
@@ -1 +1 @@
-!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var o=window.Prism,h={js:"javascript",py:"python",rb:"ruby",ps1:"powershell",psm1:"powershell",sh:"bash",bat:"batch",h:"c",tex:"latex"},g="data-src-status",u="loading",c="loaded",d="pre[data-src]:not(["+g+'="'+c+'"]):not(['+g+'="'+u+'"])',n=/\blang(?:uage)?-([\w-]+)\b/i;o.hooks.add("before-highlightall",function(e){e.selector+=", "+d}),o.hooks.add("before-sanity-check",function(e){var t=e.element;if(t.matches(d)){e.code="",t.setAttribute(g,u);var i=t.appendChild(document.createElement("CODE"));i.textContent="Loading…";var n=t.getAttribute("data-src"),a=e.language;if("none"===a){var s=(/\.(\w+)$/.exec(n)||[,"none"])[1];a=h[s]||s}f(i,a),f(t,a);var l=o.plugins.autoloader;l&&l.loadLanguages(a);var r=new XMLHttpRequest;r.open("GET",n,!0),r.onreadystatechange=function(){4==r.readyState&&(r.status<400&&r.responseText?(t.setAttribute(g,c),i.textContent=r.responseText,o.highlightElement(i)):(t.setAttribute(g,"failed"),400<=r.status?i.textContent=function(e,t){return"✖ Error "+e+" while fetching file: "+t}(r.status,r.statusText):i.textContent="✖ Error: File does not exist or is empty"))},r.send(null)}});var e=!(o.plugins.fileHighlight={highlight:function(e){for(var t,i=(e||document).querySelectorAll(d),n=0;t=i[n++];)o.highlightElement(t)}});o.fileHighlight=function(){e||(console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead."),e=!0),o.plugins.fileHighlight.highlight.apply(this,arguments)}}function f(e,t){var i=e.className;i=i.replace(n," ")+" language-"+t,e.className=i.replace(/\s+/g," ").trim()}}();
\ No newline at end of file
+!function(){if("undefined"!=typeof self&&self.Prism&&self.document){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector);var r=window.Prism,h={js:"javascript",py:"python",rb:"ruby",ps1:"powershell",psm1:"powershell",sh:"bash",bat:"batch",h:"c",tex:"latex"},g="data-src-status",c="loading",u="loaded",p="pre[data-src]:not(["+g+'="'+u+'"]):not(['+g+'="'+c+'"])',i=/\blang(?:uage)?-([\w-]+)\b/i;r.hooks.add("before-highlightall",function(e){e.selector+=", "+p}),r.hooks.add("before-sanity-check",function(e){var t=e.element;if(t.matches(p)){e.code="",t.setAttribute(g,c);var n=t.appendChild(document.createElement("CODE"));n.textContent="Loading…";var i=t.getAttribute("data-src"),a=e.language;if("none"===a){var s=(/\.(\w+)$/.exec(i)||[,"none"])[1];a=h[s]||s}d(n,a),d(t,a);var l=r.plugins.autoloader;l&&l.loadLanguages(a);var o=new XMLHttpRequest;o.open("GET",i,!0),o.onreadystatechange=function(){4==o.readyState&&(o.status<400&&o.responseText?(t.setAttribute(g,u),n.textContent=o.responseText,r.highlightElement(n)):(t.setAttribute(g,"failed"),400<=o.status?n.textContent=function(e,t){return"✖ Error "+e+" while fetching file: "+t}(o.status,o.statusText):n.textContent="✖ Error: File does not exist or is empty"))},o.send(null)}});var e=!(r.plugins.fileHighlight={highlight:function(e){for(var t,n=(e||document).querySelectorAll(p),i=0;t=n[i++];)r.highlightElement(t)}});r.fileHighlight=function(){e||(console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead."),e=!0),r.plugins.fileHighlight.highlight.apply(this,arguments)}}function d(e,t){var n=e.className;n=n.replace(i," ")+" language-"+t,e.className=n.replace(/\s+/g," ").trim()}}();
\ No newline at end of file
diff --git a/prism.js b/prism.js
index 487be2b..c25249c 100644
--- a/prism.js
+++ b/prism.js
@@ -1566,6 +1566,11 @@ Prism.languages.js = Prism.languages.javascript;
 		return;
 	}
 
+	// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
+	if (!Element.prototype.matches) {
+		Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
+	}
+
 	var Prism = window.Prism;
 
 	var LOADING_MESSAGE = 'Loading…';