Sha256: e4aaa47fa6a8950279faaf01b4ae6135e0e2d0450143c402bc96daf99cdd6de3

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

(function(){

if (!self.Prism || !self.document || !document.querySelector) {
	return;
}

var Extensions = {
	'js': 'javascript',
	'html': 'markup',
	'svg': 'markup',
	'xml': 'markup',
	'py': 'python',
	'rb': 'ruby'
};

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);
});

})();

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyhyhy-1.0.0 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.9 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.8 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.7 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.6 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.5 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js
hyhyhy-0.0.4 lib/hyhyhy/structure/_includes/prism/plugins/file-highlight/prism-file-highlight.js