forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typeahead for syntax highlighting languages.
Modified composebox_typeahead.js to recognize the triple backtick and tilde for code blocks, and added appropriate typeahead functions in that file and in typeahead_helper.js. Additionally, a new file pygments_data.js contains a dictionary of the supported languages, mapping to relative popularity rankings. These rankings determine the order of sort of the languages in the typeahead. This JavaScript file is actually in static/generated/pygments_data.js, as it is generated by a Python script, tools/build_pymgents_data.py. This is so that if Pygments adds support for new languages, the JavaScript file will be updated appropriately. This python script uses a set of popularity rankings defined in lang.json. Corresponding unit tests were also added. Fixes zulip#4111.
- Loading branch information
Showing
13 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,16 @@ assert.deepEqual(test_streams[2].name, "Derp"); // Less subscribers | |
assert.deepEqual(test_streams[3].name, "Dev"); // Alphabetically last | ||
assert.deepEqual(test_streams[4].name, "dead"); // Inactive streams last | ||
|
||
set_global('pygments_data', {langs: | ||
{python: 40, javscript: 50, php: 38, pascal: 29, perl: 22, css: 0}, | ||
}); | ||
|
||
var test_langs = ["pascal", "perl", "php", "python", "javascript"]; | ||
test_langs = typeahead_helper.sort_languages(test_langs, "p"); | ||
|
||
// Sort languages by matching first letter, and then by popularity | ||
assert.deepEqual(test_langs, ["python", "php", "pascal", "perl", "javascript"]); | ||
|
||
var matches = [ | ||
{ | ||
email: "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
|
||
from pygments.lexers import get_all_lexers | ||
import json | ||
import os | ||
|
||
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../') | ||
DATA_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'lang.json') | ||
JS_PATH = os.path.join(ZULIP_PATH, 'static', 'generated', 'pygments_data.js') | ||
|
||
with open(DATA_PATH) as f: | ||
langs = json.load(f) | ||
|
||
lexers = get_all_lexers() | ||
for lexer in lexers: | ||
for name in lexer[1]: | ||
if name not in langs: | ||
langs[name] = 0 | ||
|
||
template = '''var pygments_data = (function () { | ||
var exports = {}; | ||
exports.langs = %s; | ||
return exports; | ||
}()); | ||
if (typeof module !== 'undefined') { | ||
module.exports = pygments_data; | ||
}''' % json.dumps(langs) | ||
|
||
with open(JS_PATH, 'w') as f: | ||
f.write(template) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"abap": 27, | ||
"ada": 25, | ||
"awk": 1, | ||
"bash": 7, | ||
"c": 49, | ||
"c#": 47, | ||
"c++": 48, | ||
"cobol": 26, | ||
"cpp": 48, | ||
"csharp": 47, | ||
"css": 48, | ||
"d": 29, | ||
"dart": 28, | ||
"delphi": 42, | ||
"erlang": 10, | ||
"fsharp": 19, | ||
"go": 34, | ||
"groovy": 13, | ||
"haskell": 15, | ||
"html": 30, | ||
"java": 50, | ||
"javascript": 51, | ||
"js": 43, | ||
"julia": 4, | ||
"latex": 40, | ||
"lisp": 18, | ||
"lua": 22, | ||
"mask": 2, | ||
"math": 50, | ||
"matlab": 33, | ||
"mql": 9, | ||
"mql4": 9, | ||
"objective-c": 35, | ||
"objectivec": 35, | ||
"objectpascal": 42, | ||
"pascal": 42, | ||
"perl": 40, | ||
"php": 44, | ||
"pl": 40, | ||
"prolog": 16, | ||
"python": 46, | ||
"quote": 50, | ||
"r": 37, | ||
"rb": 39, | ||
"ruby": 39, | ||
"rust": 8, | ||
"sas": 30, | ||
"scala": 21, | ||
"scheme": 14, | ||
"sql": 32, | ||
"swift": 41, | ||
"tex": 40, | ||
"vb.net": 45, | ||
"vbnet": 45, | ||
"xml": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ZULIP_VERSION = "1.5.1+git" | ||
PROVISION_VERSION = '4.20' | ||
PROVISION_VERSION = '4.21' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters