Merge pull request #514 from hiulit/gh-pages Added fileHighlight function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/plugins/file-highlight/prism-file-highlight.js b/plugins/file-highlight/prism-file-highlight.js
index 0dd7eda..c81dd01 100644
--- a/plugins/file-highlight/prism-file-highlight.js
+++ b/plugins/file-highlight/prism-file-highlight.js
@@ -1,56 +1,61 @@
-(function(){
-
-if (!self.Prism || !self.document || !document.querySelector) {
- return;
-}
-
-var Extensions = {
- 'js': 'javascript',
- 'html': 'markup',
- 'svg': 'markup',
- 'xml': 'markup',
- 'py': 'python',
- 'rb': 'ruby',
- 'ps1': 'powershell',
- 'psm1': 'powershell'
-};
-
-Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function(pre) {
- var src = pre.getAttribute('data-src');
- var extension = (src.match(/\.(\w+)$/) || [,''])[1];
- var language = Extensions[extension] || extension;
-
- var code = document.createElement('code');
- code.className = 'language-' + language;
-
- pre.textContent = '';
-
- code.textContent = 'Loading…';
-
- pre.appendChild(code);
-
- var xhr = new XMLHttpRequest();
-
- xhr.open('GET', src, true);
-
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
-
- if (xhr.status < 400 && xhr.responseText) {
- code.textContent = xhr.responseText;
-
- Prism.highlightElement(code);
- }
- else if (xhr.status >= 400) {
- code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
- }
- else {
- code.textContent = '✖ Error: File does not exist or is empty';
- }
- }
+(function () {
+ if (!self.Prism || !self.document || !document.querySelector) {
+ return;
+ }
+
+ self.Prism.fileHighlight = function() {
+
+ var Extensions = {
+ 'js': 'javascript',
+ 'html': 'markup',
+ 'svg': 'markup',
+ 'xml': 'markup',
+ 'py': 'python',
+ 'rb': 'ruby',
+ 'ps1': 'powershell',
+ 'psm1': 'powershell'
+ };
+
+ Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function(pre) {
+ var src = pre.getAttribute('data-src');
+ var extension = (src.match(/\.(\w+)$/) || [,''])[1];
+ var language = Extensions[extension] || extension;
+
+ var code = document.createElement('code');
+ code.className = 'language-' + language;
+
+ pre.textContent = '';
+
+ code.textContent = 'Loading…';
+
+ pre.appendChild(code);
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.open('GET', src, true);
+
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+
+ if (xhr.status < 400 && xhr.responseText) {
+ code.textContent = xhr.responseText;
+
+ Prism.highlightElement(code);
+ }
+ else if (xhr.status >= 400) {
+ code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
+ }
+ else {
+ code.textContent = '✖ Error: File does not exist or is empty';
+ }
+ }
+ };
+
+ xhr.send(null);
+ });
+
};
-
- xhr.send(null);
-});
+
+ self.Prism.fileHighlight();
})();