-
Notifications
You must be signed in to change notification settings - Fork 5
/
prism-langs.js
97 lines (80 loc) · 2.6 KB
/
prism-langs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* eslint-disable no-console */
const https = require('https');
// Match version number to included copy
https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.json', (res) => {
res.setEncoding('utf8');
let body = '';
res.on('data', (data) => {
body += data;
});
res.on('end', () => {
const components = JSON.parse(body);
const highlights = {};
// Split markup
for (const id in components.languages.markup.aliasTitles) {
if (!Object.prototype.hasOwnProperty.call(components.languages.markup.aliasTitles, id)) continue;
components.languages[id] = {
title: components.languages.markup.aliasTitles[id]
};
}
for (const id in components.languages) {
if (id === 'meta') continue;
if (id === 'markup') continue;
const lang = components.languages[id];
const name = lang.title || lang;
const contents = [];
let alias = lang.alias;
if (typeof alias === 'string') alias = [alias];
if (alias) {
for (let i = 0, l = alias.length; i < l; i++) {
contents.push(alias[i]);
}
}
highlights[id] = {
name
};
if (contents.length > 0) {
highlights[id].alias = contents;
}
}
// Default option
highlights[''] = {
name: 'Plain text'
};
// Manual overrides
highlights.asm6502.alias = ['asm'];
highlights.aspnet.alias = ['dotnet'];
highlights.sqf.name = 'SQF';
highlights.cpp.alias = ['cpp'];
highlights.csharp.alias.push('csharp', '.net');
highlights.csp.alias = ['csp'];
highlights['dns-zone-file'].alias.push('bind', 'named');
highlights.hpkp.alias = ['hpkp'];
highlights['js-extras'].name = 'JavaScript Extras';
highlights['js-templates'].name = 'JavaScript Templates';
highlights.json.alias = ['javascript object notation'];
highlights.json5.alias = ['javascript object notation'];
highlights.jsonp.alias = ['javascript object notation'];
highlights.nasm.alias = ['assembly'];
highlights.protobuf.alias = ['protobuf'];
highlights.pug.alias = ['jade'];
highlights.regex.alias = ['regular expression'];
highlights['shell-session'].alias = ['terminal', 'console'];
highlights['solution-file'].name = 'Visual Studio Solution';
highlights['solution-file'].alias.push('.net', 'dotnet');
highlights.vbnet.name = 'Visual Basic .NET';
highlights.vbnet.alias = ['vb', 'dotnet'];
highlights.wasm.alias = ['wasm', 'asm'];
// Sort
const ordered = {};
Object.keys(highlights).sort().forEach((key) => {
ordered[key] = highlights[key];
});
// Format output
console.log(JSON.stringify(ordered)
.slice(1, -1)
.replace(/},"/g, '},\n"')
.replace(/:/g, ': ')
.replace(/,/g, ', '));
});
});