Skip to content

Commit

Permalink
feat(highlighter): handle more nunjucks/jinja like file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
levito committed Apr 26, 2020
1 parent c33d3d1 commit 52f61d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/core/highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
const HighlightJs = require('highlight.js');
const _ = require('lodash');

const langMap = new Map([
['nunjucks', 'django'],
['nunj', 'django'],
]);

module.exports = function highlighter(content, lang) {
content = _.toString(content || '');
lang = langMap.get(lang) || lang;
lang = lang ? lang.toLowerCase() : lang;
try {
return lang ? HighlightJs.highlight(lang, content).value : HighlightJs.highlightAuto(content).value;
Expand Down
28 changes: 22 additions & 6 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ const Stream = require('stream');
module.exports = {

lang(filePath) {
return fang(filePath) || {
name: Path.parse(filePath).ext.replace('.', '').toUpperCase(),
mode: 'text',
scope: null,
color: null,
};
const name = Path.parse(filePath).ext.replace('.', '').toUpperCase();
switch (name) {
case 'NUNJUCKS':
case 'NUNJS':
case 'NUNJ':
case 'NJ':
case 'JINJA2':
case 'J2':
return {
name: 'HTML+Django',
mode: 'django',
scope: 'text.html.django',
color: null,
};
default:
return fang(filePath) || {
name: name,
mode: 'text',
scope: null,
color: null,
};
}
},

titlize(str) {
Expand Down

0 comments on commit 52f61d3

Please sign in to comment.