lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js in gollum-2.2.3 vs lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js in gollum-2.2.4
- old
+ new
@@ -192,12 +192,12 @@
ieSafePreviewSet( text );
previewSet = ieSafePreviewSet;
}
};
-// 'c', 'c++', 'cpp' are github specific and transformed to c_cpp for Ace.
-// 'coffeescript' is transformed to 'coffee' for Ace.
+// See pygmentsLanguageToAceMode for pygment to ace mode translations.
+// TODO: Update languages and translation once Ace is upgraded to v1.0.
var languages = [ 'c', 'c++', 'cpp', 'clojure', 'coffee',
'coffeescript', 'coldfusion', 'csharp', 'css', 'diff', 'golang',
'groovy', 'haxe', 'html', 'java', 'javascript', 'json', 'latex',
'less', 'liquid', 'lua', 'markdown', 'ocaml', 'perl', 'pgsql', 'php',
'powershell', 'python', 'ruby', 'scad', 'scala', 'scss', 'sh', 'sql',
@@ -242,10 +242,35 @@
var newDiv = doc.createElement('div');
newDiv.innerHTML = color.html;
element.parentNode.parentNode.replaceChild( newDiv, element.parentNode );
}
+// Pygments and Ace have different names for languages.
+function pygmentsLanguageToAceMode( declaredLanguage ) {
+ declaredLanguage = declaredLanguage.toLowerCase();
+
+ switch ( declaredLanguage ) {
+ case 'bash':
+ return 'sh';
+ case 'c':
+ case 'c++':
+ case 'cpp':
+ case 'objective-c':
+ return 'c_cpp';
+ case 'c#':
+ return 'csharp';
+ case 'coffeescript':
+ return 'coffee';
+ case 'html+erb':
+ return 'html'
+ }
+
+ // Assume language name is the same
+ // if it's not handled above.
+ return declaredLanguage;
+}
+
var makePreviewHtml = function () {
var text = editorSession.getValue();
if ( text == undefined || text == '' ) {
previewSet( '' );
@@ -292,24 +317,10 @@
}
var txt = codeHTML.split( /\b/ );
// the syntax for code highlighting means all code, even one line, contains newlines.
if ( txt.length > 1 && codeHTML.match( /\n/ ) ) {
var declaredLanguage = element.className.toLowerCase();
- var aceMode = declaredLanguage;
-
- // GitHub supports 'c', 'c++', 'cpp'
- // which must trigger the 'c_cpp' mode in Ace.
- if ( declaredLanguage === 'c' ||
- declaredLanguage === 'c++' ||
- declaredLanguage === 'cpp' ) {
- aceMode = 'c_cpp';
- }
-
- // Pygments's name for CoffeeScript is 'coffeescript', but Ace
- // calls it 'coffee'.
- if ( declaredLanguage === 'coffeescript' ) {
- aceMode = 'coffee';
- }
+ var aceMode = pygmentsLanguageToAceMode( declaredLanguage );
if ( $.inArray( declaredLanguage, languages ) === -1 ) {
// Unsupported language.
skipped++;
continue;