├── .gitignore ├── src └── templates │ ├── language │ ├── languages │ └── page ├── readme.md ├── package.json ├── LICENSE └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !.gitignore 3 | !LICENSE 4 | !index.js 5 | !package.json 6 | !readme.md 7 | !src/ 8 | -------------------------------------------------------------------------------- /src/templates/language: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{label}} 5 | 6 | 7 | 8 | {{#ids}}{{.}} • {{/ids}} 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Generate markdown document listing valid language identifier keywords for enabling syntax highlighting in GitHub Flavored Markdown. 2 | 3 | ``` 4 | $ npm install 5 | $ node . --linguist-version=VERSION --lang-yml-path=PATH/TO/languages.yml 6 | ``` 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "main": "index.js", 4 | "license": "MIT", 5 | "author": "Jesse McCarthy (http://software.jessemccarthy.net/)", 6 | "dependencies": { 7 | "js-yaml": "1.x", 8 | "lodash": "3.x", 9 | "mustache": "1.x" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/templates/languages: -------------------------------------------------------------------------------- 1 | # By Language 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | {{#languages}} 19 | {{{.}}} 20 | {{/languages}} 21 | 22 | 23 |
8 | Language 9 | 12 | IDs 13 |
24 | -------------------------------------------------------------------------------- /src/templates/page: -------------------------------------------------------------------------------- 1 | These are the language IDs to use in [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/) to enable syntax highlightling. This list was extracted from [Linguist](https://github.com/github/linguist) version {{linguist_version}}. See Linguist's [lib/linguist/languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) for the most up to date values. 2 | 3 | For example, this snippet uses the `js` ID to enable JavaScript syntax: 4 | 5 | ```js 6 | console.log(x); 7 | ``` 8 | 9 | Language IDs are case-insensitive and may be specified with or without a `.` prepended. If there is an ID `whatever`, then `.whatever`, `.WHATever`, and `whatEVER` are equivalent. 10 | 11 | {{{languages}}} 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | Copyright (c) 2015 Jesse McCarthy (http://software.jessemccarthy.net/) 3 | (https://github.com/jmm) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var 2 | yaml = require('js-yaml'), 3 | path = require('path'), 4 | fs = require('fs'), 5 | _ = require('lodash'), 6 | mustache = require('mustache'), 7 | args = {}, 8 | // Input from languages.yml. 9 | lang_data, 10 | // Processed language data. 11 | languages = {}, 12 | // Data about language groups. 13 | groups = {}, 14 | // Sorted array of languages. 15 | sequence, 16 | // Rendered output. 17 | content = [], 18 | // Functions to apply to language data in successive passes. 19 | passes = [], 20 | encoding = 'utf8', 21 | paths = {output: {dir: 'dist', file: 'languages.md'}}; 22 | 23 | process.argv.slice(2).forEach(function (arg) { 24 | var matches = arg.match(/--([^=]+)=([^ ]+)/); 25 | args[matches[1]] = matches[2]; 26 | }); 27 | 28 | if (! args['linguist-version']) { 29 | throw "You must specify linguist version"; 30 | } 31 | 32 | paths.lang_yml = 33 | args['lang-yml-path'] || './linguist/lib/linguist/languages.yml'; 34 | 35 | lang_data = yaml.safeLoad(fs.readFileSync(paths.lang_yml, encoding)); 36 | 37 | // Get case-insensitive sort of top level keys (language names). 38 | sequence = Object.keys(lang_data).sort(function (a, b) { 39 | var ret = 0; 40 | a = a.toLowerCase(); 41 | b = b.toLowerCase(); 42 | if (a < b) { 43 | ret = -1; 44 | } 45 | else if (a > b) { 46 | ret = 1; 47 | } 48 | return ret; 49 | }); 50 | 51 | // Compile language data. 52 | sequence.forEach(function (key) { 53 | var 54 | lang = lang_data[key], 55 | group = lang.group || key; 56 | 57 | function lc (val) { 58 | return val.toLowerCase(); 59 | } 60 | 61 | function despace (val) { 62 | return val.replace(/ /g, "-"); 63 | } 64 | 65 | languages[key] = { 66 | key: key, 67 | label: key, 68 | group: group, 69 | // Do not include group name here, it's not always applicable. For example, 70 | // see "Ecere Projects". Its group is "JavaScript", but it has special 71 | // highlighting. 72 | ids: _.union( 73 | [ 74 | despace(lc(key)), 75 | ], 76 | 77 | (lang.aliases || []) 78 | .filter(function (el) { 79 | return el.indexOf(" ") === -1; 80 | }) 81 | .map(lc), 82 | 83 | (lang.extensions || []) 84 | .map(lc).map(function (val) { 85 | // Extract name without leading "." 86 | return val.match(/([^.].*)/)[1]; 87 | }) 88 | ).sort() 89 | }; 90 | 91 | // To accumulate ids for groups 92 | groups[group] = groups[group] || {ids: []}; 93 | }); 94 | 95 | // Retrieve template. 96 | function get_template (id) { 97 | return fs.readFileSync('./src/templates/' + id, 'utf8'); 98 | } 99 | 100 | // Render template. 101 | function render (template, context) { 102 | template = get_template(template); 103 | return mustache.render.apply(mustache, [template, context]); 104 | } 105 | 106 | // Accumulate ids per group. 107 | passes.push(function (item) { 108 | var group = groups[item.group]; 109 | group.ids = _.union(group.ids, item.ids).sort(); 110 | }); 111 | 112 | // Render content for language. 113 | passes.push(function (item) { 114 | content.push(render('language', item)); 115 | }); 116 | 117 | passes.forEach(function (handler) { 118 | sequence.forEach(function (name) { 119 | handler(languages[name]); 120 | }); 121 | }); 122 | 123 | content = render('languages', {languages: content}); 124 | content = render('page', { 125 | languages: content, 126 | linguist_version: args['linguist-version'], 127 | }); 128 | 129 | try { 130 | fs.mkdirSync('./' + paths.output.dir, '0755'); 131 | } 132 | catch (e) {} 133 | 134 | fs.writeFileSync( 135 | './' + path.join(paths.output.dir, paths.output.file), 136 | content, 137 | {encoding: encoding} 138 | ); 139 | --------------------------------------------------------------------------------