Skip to content

Commit

Permalink
Blacklist languages instead of extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Oct 12, 2016
1 parent 544989b commit 9c0d2f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
13 changes: 5 additions & 8 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
font: 'Inconsolata',
fontSize: 'medium',
lineNumbers: true,
extBlacklist: ''
languageBlacklist: ''
};

const OPTIONS = Object.keys(OPTIONS_DEFAULTS);
Expand Down Expand Up @@ -122,11 +122,11 @@
return filename.split('.').pop();
}

function isExtensionBlacklisted(extension) {
var blacklist = localStorage.getItem('extBlacklist').split(/[\s,]+/);
function isLanguageBlacklisted(language) {
var blacklist = localStorage.getItem('languageBlacklist').split(/[\s,]+/);
var index, length = blacklist.length;
for (index = 0; index < length; index++) {
if (blacklist[index].toLowerCase() === extension) {
if (blacklist[index].toLowerCase() === language) {
return true;
}
}
Expand All @@ -142,9 +142,6 @@
if (BROWSER_CONTENT.indexOf(contentType) != -1) {
return null;
}
if (isExtensionBlacklisted(extension)) {
return null;
}
return !!LANG_EXT_MAP[fragment] ? fragment : EXT_LANG_MAP[contentType] ||
EXT_LANG_MAP[extension] ||
EXT_LANG_MAP[filename];
Expand All @@ -171,7 +168,7 @@
var filename = getFilenameFromUrl(details.url);
var extension = getExtensionFromFilename(filename);
var language = detectLanguage(contentType, fragment, filename, extension);
if (!language) {
if (!language || isLanguageBlacklisted(language)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
hljs.highlightBlock(codeEl);
}
},
extBlacklist: {
selector: '#ext-blacklist',
languageBlacklist: {
selector: '#language-blacklist',
value: 'value',
decode: id,
render: function(value) {}
Expand Down
4 changes: 2 additions & 2 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ <h3>Select your font size</h3>
<option value="x-large">x-large</option>
<option value="xx-large">xx-large</option>
</select>
<h3>Blacklist Extensions</h3>
<textarea id="ext-blacklist"></textarea>
<h3>Blacklist Languages</h3>
<textarea id="language-blacklist"></textarea>
<h3>Line numbers:<input id="line-numbers" type="checkbox"></h3>
<pre id="code" class="go">
package main
Expand Down

0 comments on commit 9c0d2f9

Please sign in to comment.