Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoring languages #85

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 14 additions & 2 deletions 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,
ignoreLanguages: ''
};

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

function isLanguageIgnored(language) {
var ignored = localStorage.getItem('ignoreLanguages').split(/[\s,]+/);
var index, length = ignored.length;
for (index = 0; index < length; index++) {
if (ignored[index].toLowerCase() === language) {
return true;
}
}
return false;
}

function getFragmentFromUrl(url) {
var fragment = /#ft=(\w+)/.exec(url);
return fragment && fragment[1];
Expand Down Expand Up @@ -156,7 +168,7 @@
var filename = getFilenameFromUrl(details.url);
var extension = getExtensionFromFilename(filename);
var language = detectLanguage(contentType, fragment, filename, extension);
if (!language) {
if (!language || isLanguageIgnored(language)) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
function id(a) { return a }
function eq(b) { return function(a) { return a === b } }
function val(obj, key) { return obj[key] }
function noop() {}
function set(sel, path, fn) {
var parts = path.split('.');
var target = parts[parts.length-1];
Expand Down Expand Up @@ -43,6 +44,12 @@
codeEl.innerHTML = codeEl.textContent;
hljs.highlightBlock(codeEl);
}
},
ignoreLanguages: {
selector: '#ignore-languages',
value: 'value',
decode: id,
render: noop
}
};

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>Ignore Languages</h3>
<textarea id="ignore-languages"></textarea>
<h3>Line numbers:<input id="line-numbers" type="checkbox"></h3>
<pre id="code" class="go">
package main
Expand Down