TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/317150

Change subject: Convert SyntaxHighlight names to Ace names
......................................................................

Convert SyntaxHighlight names to Ace names

Provide a translation from Syntaxhighlight compatible Pygments and
GeSHi language names to CodeEditor compatible Ace lexer names

Now when you select php4, the CodeEditor will use the Ace lexer php,
instead of falling back to text mode.

Bug: T148515
Change-Id: Ibc209f97318614f764457726f8d55f4e15276d79
---
M ResourceLoaderGeSHiVisualEditorModule.php
A SyntaxHighlight_GeSHi.ace.php
M extension.json
M modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js
M modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js
5 files changed, 228 insertions(+), 9 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SyntaxHighlight_GeSHi 
refs/changes/50/317150/1

diff --git a/ResourceLoaderGeSHiVisualEditorModule.php 
b/ResourceLoaderGeSHiVisualEditorModule.php
index 123fcd1..64c1e41 100644
--- a/ResourceLoaderGeSHiVisualEditorModule.php
+++ b/ResourceLoaderGeSHiVisualEditorModule.php
@@ -29,8 +29,18 @@
                $scripts = parent::getScript( $context );
 
                return $scripts . Xml::encodeJsCall(
-                       've.dm.MWSyntaxHighlightNode.static.addLanguages', 
array(
-                               $this->getLanguages()
+                       
've.dm.MWSyntaxHighlightNode.static.addPygmentsLanguages', array(
+                               $this->getPygmentsLanguages()
+                       ),
+                       ResourceLoader::inDebugMode()
+               ) . Xml::encodeJsCall(
+                       
've.dm.MWSyntaxHighlightNode.static.addGeshiToPygmentsMap', array(
+                               GeSHi::$compatibleLexers
+                       ),
+                       ResourceLoader::inDebugMode()
+               ) . Xml::encodeJsCall(
+                       
've.dm.MWSyntaxHighlightNode.static.addPygmentsToAceMap', array(
+                               SyntaxHighlightAce::getPygmentsToAceMap()
                        ),
                        ResourceLoader::inDebugMode()
                );
@@ -47,9 +57,9 @@
         * Get a full list of available langauges
         * @return array
         */
-       private function getLanguages() {
+       private function getPygmentsLanguages() {
                $lexers = require __DIR__ . '/SyntaxHighlight_GeSHi.lexers.php';
-               return array_merge( $lexers, array_keys( 
GeSHi::$compatibleLexers ) );
+               return $lexers;
        }
 
        public function enableModuleContentVersion() {
diff --git a/SyntaxHighlight_GeSHi.ace.php b/SyntaxHighlight_GeSHi.ace.php
new file mode 100644
index 0000000..2d358ea
--- /dev/null
+++ b/SyntaxHighlight_GeSHi.ace.php
@@ -0,0 +1,174 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Class provides functionality to map Ace lexer definitions
+ */
+class SyntaxHighlightAce
+ {
+       /** @var array This map is inverted, because it is easier to maintain 
this way */
+       private static $aceLexers = [
+               'ABAP'                  =>      [ 'abap' ],
+               'ABC'                   =>      [],
+               'ActionScript'  =>      [ 'actionscript', 'actionscript3' ],
+               'ADA'                   =>      [ 'ada', 'ada2005', 'ada95' ],
+               'Apache_Conf'   =>      [ 'apache', 'apacheconf', 'aconf'],
+               'AsciiDoc'              =>      [],
+               'Assembly_x86'  =>      [ 'nasm' ],
+               'AutoHotKey'    =>      [ 'autohotkey', 'ah' ],
+               'BatchFile'             =>      [ 'bat', 'batch', 'dosbatch', 
'winbatch' ],
+               'C_Cpp'                 =>      [ 'cpp', 'c++' ],
+               'C9Search'              =>      [],
+               'Cirru'                 =>      [ 'cirru' ],
+               'Clojure'               =>      [ 'clojure', 'clj' ],
+               'Cobol'                 =>      [ 'cobol' ],
+               'coffee'                =>      [ 'coffee', 'coffeescript', 
'coffee-script' ],
+               'ColdFusion'    =>      [ 'cfm' ],
+               'CSharp'                =>      [ 'csharp', '#' ],
+               'CSS'                   =>      [ 'css' ],
+               'Curly'                 =>      [],
+               'D'                             =>      [ 'd' ],
+               'Dart'                  =>      [ 'dart' ],
+               'Diff'                  =>      [ 'diff', 'udiff' ],
+               'Dockerfile'    =>      [ 'Dockerfile', 'docker' ],
+               'Dot'                   =>      [],
+               'Dummy'                 =>      [],
+               'DummySyntax'   =>      [],
+               'Eiffel'                =>      [ 'eiffel' ],
+               'EJS'                   =>      [],
+               'Elixir'                =>      [ 'elixer', 'ex', 'exs' ],
+               'Elm'                   =>      [ 'elm' ],
+               'Erlang'                =>      [ 'erlang' ],
+               'Forth'                 =>      [],
+               'Fortran'               =>      [ 'fortran' ],
+               'FTL'                   =>      [],
+               'Gcode'                 =>      [],
+               'Gherkin'               =>      [ 'cucumber', 'gherkin' ],
+               'Gitignore'             =>      [],
+               'Glsl'                  =>      [ 'glsl' ],
+               'Gobstones'             =>      [],
+               'golang'                =>      [ 'go' ],
+               'Groovy'                =>      [ 'groovy' ],
+               'HAML'                  =>      [ 'haml' ],
+               'Handlebars'    =>      [ 'html+handlebars' ],
+               'Haskell'               =>      [ 'haskell', 'hs' ],
+               'haXe'                  =>      [ 'hx', 'haxe', 'hxsl' ],
+               'HTML'                  =>      [ 'html' ],
+               'HTML_Elixir'   =>      [],
+               'HTML_Ruby'             =>      [ 'rhtml', 'html+erb', 
'html+ruby' ],
+               'INI'                   =>      [ 'ini', 'cfg', 'dosini' ],
+               'Io'                    =>      [ 'io' ],
+               'Jack'                  =>      [ '' ],
+               'Jade'                  =>      [ 'jade' ],
+               'Java'                  =>      [ 'java' ],
+               'JavaScript'    =>      [ 'Javascript', 'js' ],
+               'JSON'                  =>      [ 'json' ],
+               'JSONiq'                =>      [],
+               'JSP'                   =>      [ 'jsp' ],
+               'JSX'                   =>      [],
+               'Julia'                 =>      [ 'julia', 'jl' ],
+               'LaTeX'                 =>      [ 'latex' ],
+               'Lean'                  =>      [ 'lean' ],
+               'LESS'                  =>      [ 'less' ],
+               'Liquid'                =>      [ 'liquid' ],
+               'Lisp'                  =>      [ 'lisp', 'common-lisp', 'cl' ],
+               'LiveScript'    =>      [ 'Livescript', 'live-script' ],
+               'LogiQL'                =>      [],
+               'LSL'                   =>      [ 'lsl' ],
+               'Lua'                   =>      [ 'lua' ],
+               'LuaPage'               =>      [],
+               'Lucene'                =>      [],
+               'Makefile'              =>      [ 'make', 'makefile', 'mf', 
'bsdmake' ],
+               'Markdown'              =>      [],
+               'Mask'                  =>      [ 'mask' ],
+               'MATLAB'                =>      [ 'matlab' ],
+               'Maze'                  =>      [],
+               'MEL'                   =>      [],
+               'MUSHCode'              =>      [],
+               'MySQL'                 =>      [ 'mysql' ],
+               'Nix'                   =>      [ 'nix', 'nixos' ],
+               'NSIS'                  =>      [ 'nsis', 'nsi', 'nsh' ],
+               'ObjectiveC'    =>      [ 'objectivec', 'objective-c', 'obj-c', 
'objc', 'objective-c++', 'objectivec++', 'obj-c++', 'objc++' ],
+               'OCaml'                 =>      [ 'ocaml' ],
+               'Pascal'                =>      [ 'pascal', 'delphi', 'pas', 
'objectpascal' ],
+               'Perl'                  =>      [ 'perl', 'pl', 'perl6', 'pl6' 
],
+               'pgSQL'                 =>      [ 'postgresql', 'postgres' ],
+               'PHP'                   =>      [ 'php', 'php3', 'php4', 
'php5', 'html+php' ],
+               'Powershell'    =>      [ 'powershell', 'posh', 'ps1', 'psm1'],
+               'Praat'                 =>      [ 'praat' ],
+               'Prolog'                =>      [ 'prolog' ],
+               'Properties'    =>      [ 'properties', 'jproperties' ],
+               'Protobuf'              =>      [ 'protobuf', 'proto' ],
+               'Python'                =>      [ 'python', 'py', 'sage', 
'pyton3', 'py3' ],
+               'R'                             =>      [],
+               'Razor'                 =>      [],
+               'RDoc'                  =>      [],
+               'RHTML'                 =>      [], // HTML with Rcode, not ruby
+               'RST'                   =>      [ 'rst', 'rest', 
'restructuredtext' ],
+               'Ruby'                  =>      [ 'ruby', 'rb', 'duby' ],
+               'Rust'                  =>      [ 'rust' ],
+               'SASS'                  =>      [ 'sass' ],
+               'SCAD'                  =>      [],
+               'Scala'                 =>      [ 'scala' ],
+               'Scheme'                =>      [ 'scheme', 'scm' ],
+               'SCSS'                  =>      [ 'scss' ],
+               'SH'                    =>      [ 'sh', 'bash', 'ksh', 'shell' 
],
+               'SJS'                   =>      [],
+               'Smarty'                =>      [ 'smarty', 'html+smarty' ],
+               'snippets'              =>      [],
+               'Soy_Template'  =>      [],
+               'Space'                 =>      [],
+               'SQL'                   =>      [ 'sql' ],
+               'SQLServer'             =>      [],
+               'Stylus'                =>      [],
+               'SVG'                   =>      [],
+               'Swift'                 =>      [ 'swift' ],
+               'Tcl'                   =>      [ 'tcl' ],
+               'Tex'                   =>      [ 'tex' ],
+               'Text'                  =>      [ 'text' ],
+               'Textile'               =>      [],
+               'Toml'                  =>      [],
+               'Twig'                  =>      [ 'html+twig', 'twig' ],
+               'Typescript'    =>      [ 'typescript', 'ts' ],
+               'Vala'                  =>      [ 'vala', 'vapi' ],
+               'VBScript'              =>      [],
+               'Velocity'              =>      [ 'velocity', 'html+velocity' ],
+               'Verilog'               =>      [ 'verilog', 'v', 
'systemverilog', 'sv' ],
+               'VHDL'                  =>      [ 'vhdl' ],
+               'Wollok'                =>      [],
+               'XML'                   =>      [ 'xml' ],
+               'XQuery'                =>      [ 'xquery', 'xqy', 'xq', 'xql', 
'xqm' ],
+               'YAML'                  =>      [ 'yaml' ],
+               'Django'                =>      [ 'django', 'html+django', 
'html+jinja', 'htmldjango'],
+       ];
+
+       public static function getPygmentsToAceMap() {
+               $result = [];
+               foreach ( self::$aceLexers as $aceName => $pygmentsLexers ) {
+                       foreach( $pygmentsLexers as $lexer ) {
+                               if( strcasecmp($lexer, $aceName) === 0 ) {
+                                       continue;
+                               }
+                               if( !array_key_exists( $lexer, $result ) ) {
+                                       $result[ $lexer ] = $aceName;
+                               }
+                       }
+               }
+               return $result;
+       }
+}
diff --git a/extension.json b/extension.json
index 5611851..eab0d93 100644
--- a/extension.json
+++ b/extension.json
@@ -24,6 +24,7 @@
        "AutoloadClasses": {
                "SyntaxHighlight_GeSHi": "SyntaxHighlight_GeSHi.class.php",
                "GeSHi": "SyntaxHighlight_GeSHi.compat.php",
+               "SyntaxHighlightAce": "SyntaxHighlight_GeSHi.ace.php",
                "ResourceLoaderGeSHiVisualEditorModule": 
"ResourceLoaderGeSHiVisualEditorModule.php"
        },
        "ExtensionFunctions": [
diff --git a/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js 
b/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js
index 2c60b33..daa64f1 100644
--- a/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js
+++ b/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js
@@ -47,16 +47,49 @@
 };
 
 ( function () {
-       var supportedLanguages = [ undefined ];
+       var supportedLanguages = [ undefined ],
+               geshiToPygmentsMap,
+               pygmentsToAceMap;
 
        /**
-        * Register supported languages.
+        * Register supported Pygments languages.
         *
         * @param {Array} languages
         */
-       ve.dm.MWSyntaxHighlightNode.static.addLanguages = function ( languages 
) {
+       ve.dm.MWSyntaxHighlightNode.static.addPygmentsLanguages = function ( 
languages ) {
                ve.batchPush( supportedLanguages, languages );
        };
+
+       /**
+        * Register map from Geshi to pygments lexer names.
+        *
+        * @param {Array} map
+        */
+       ve.dm.MWSyntaxHighlightNode.static.addGeshiToPygmentsMap = function ( 
map ) {
+               geshiToPygmentsMap = map;
+               ve.batchPush( supportedLanguages, Object.keys( 
geshiToPygmentsMap ) );
+       }
+
+       /**
+        * Register a map from pygments to Ace lexer names.
+        *
+        * @param {Array} map
+        */
+       ve.dm.MWSyntaxHighlightNode.static.addPygmentsToAceMap = function ( map 
) {
+               pygmentsToAceMap = map;
+       }
+
+       /**
+        * Converts a (valid) language as recognized by the SyntaxHighlight 
wikicode
+        * to a compatible Ace lexer name (to be used by CodeEditor)
+        *
+        * @param {string} language Language name
+        * @return {string} The name of the ace lexer
+        */
+       ve.dm.MWSyntaxHighlightNode.static.convertLanguageToAce = function( 
language ) {
+               pygmentsLanguage = geshiToPygmentsMap[ pygmentsLanguage ] || 
pygmentsLanguage;
+               return ( pygmentsToAceMap[ pygmentsLanguage ] || 
pygmentsLanguage).toLowerCase();
+       }
 
        /**
         * Check if a language is supported
@@ -69,7 +102,7 @@
        };
 
        /**
-        * Get an array of all languages
+        * Get an array of all languages (both Pygments and former GeSHi names)
         *
         * @return {Array} All currently supported languages
         */
diff --git a/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js 
b/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js
index 89963bc..8bd4916 100644
--- a/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js
+++ b/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js
@@ -91,7 +91,8 @@
        ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange.call( 
this );
 
        this.language.getInput().isValid().done( function ( valid ) {
-               dialog.input.setLanguage( valid ? 
dialog.language.getInput().getValue() : 'text' );
+               var language = 
ve.dm.MWSyntaxHighlightNode.static.convertLanguageToAce( 
dialog.language.getInput().getValue() );
+               dialog.input.setLanguage( valid ? language : 'text' );
        } );
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/317150
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc209f97318614f764457726f8d55f4e15276d79
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SyntaxHighlight_GeSHi
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to