Blame view

bower_components/prism/plugins/show-language/prism-show-language.js 2.07 KB
73bcce88   luigser   COMPONENTS
1
2
  (function(){
  
eb240478   Luigi Serra   public room cards...
3
  if (typeof self === 'undefined' || !self.Prism || !self.document) {
73bcce88   luigser   COMPONENTS
4
5
6
  	return;
  }
  
eb240478   Luigi Serra   public room cards...
7
  // The languages map is built automatically with gulp
f748e9cf   Luigi Serra   new controllet an...
8
  var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
73bcce88   luigser   COMPONENTS
9
10
11
12
13
  Prism.hooks.add('before-highlight', function(env) {
  	var pre = env.element.parentNode;
  	if (!pre || !/pre/i.test(pre.nodeName)) {
  		return;
  	}
eb240478   Luigi Serra   public room cards...
14
  	var language = Languages[env.language] || (env.language.substring(0, 1).toUpperCase() + env.language.substring(1));
73bcce88   luigser   COMPONENTS
15
  	pre.setAttribute('data-language', language);
eb240478   Luigi Serra   public room cards...
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
  
  	/* check if the divs already exist */
  	var sib = pre.previousSibling;
  	var div, div2;
  	if (sib && /\s*\bprism-show-language\b\s*/.test(sib.className) &&
  		sib.firstChild &&
  		/\s*\bprism-show-language-label\b\s*/.test(sib.firstChild.className)) {
  		div2 = sib.firstChild;
  		if (div2.getAttribute('data-language') !== language) {
  			div2.setAttribute('data-language', language);
  			div2.innerHTML = language;
  		}
  	} else {
  		div = document.createElement('div');
  		div2 = document.createElement('div');
  
  		div2.className = 'prism-show-language-label';
  		div2.setAttribute('data-language', language);
  		div2.innerHTML = language;
  
  		div.className = 'prism-show-language';
  		div.appendChild(div2);
  
  		pre.parentNode.insertBefore(div, pre);
  	}
73bcce88   luigser   COMPONENTS
41
42
43
  });
  
  })();