Skip to content

Commit

Permalink
Add support for blacklisting file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Oct 12, 2016
1 parent 9d8a47f commit 544989b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ select {
margin-bottom: 10px;
}

textarea {
margin-bottom: 10px;
}

pre {
left: -10px;
top: 10px;
Expand Down
17 changes: 16 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
theme: 'sunburst',
font: 'Inconsolata',
fontSize: 'medium',
lineNumbers: true
lineNumbers: true,
extBlacklist: ''
};

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

function isExtensionBlacklisted(extension) {
var blacklist = localStorage.getItem('extBlacklist').split(/[\s,]+/);
var index, length = blacklist.length;
for (index = 0; index < length; index++) {
if (blacklist[index].toLowerCase() === extension) {
return true;
}
}
return false;
}

function getFragmentFromUrl(url) {
var fragment = /#ft=(\w+)/.exec(url);
return fragment && fragment[1];
Expand All @@ -130,6 +142,9 @@
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 Down
6 changes: 6 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
codeEl.innerHTML = codeEl.textContent;
hljs.highlightBlock(codeEl);
}
},
extBlacklist: {
selector: '#ext-blacklist',
value: 'value',
decode: id,
render: function(value) {}
}
};

Expand Down
2 changes: 2 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +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>Line numbers:<input id="line-numbers" type="checkbox"></h3>
<pre id="code" class="go">
package main
Expand Down

0 comments on commit 544989b

Please sign in to comment.