Skip to content

Commit

Permalink
added ignoreClass and processClass tex2jax options (#36)
Browse files Browse the repository at this point in the history
* added ignoreClass and processClass tex2jax options

* Nits in options description

Co-authored-by: Ellis Michael <[email protected]>
  • Loading branch information
seanamana and emichael authored Nov 28, 2021
1 parent 58341cb commit 1345679
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 7 deletions.
5 changes: 5 additions & 0 deletions css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ td {
width: 2em;
margin-left: .5em;
}

.classBox {
width: 20em;
margin-left: .5em;
}
16 changes: 13 additions & 3 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == 'shouldTeXify') {
sendResponse({answer: should_texify(request.host),
delimiters: get_delimiters(),
skip_tags: get_skip_tags()});
skip_tags: get_skip_tags(),
ignore_class: get_ignore_class(),
process_class: get_process_class()});
} else {
sendResponse({});
}
Expand Down Expand Up @@ -95,10 +97,18 @@ function get_delimiters() {
delimiters.inline_custom = get_option('inline_custom')
delimiters.display_dollar = get_option('display_dollar');
delimiters.display_bracket = get_option('display_bracket');
delimiters.display_custom = get_option('display_custom')
delimiters.display_custom = get_option('display_custom');
return delimiters;
}

function get_skip_tags(){
return get_option('skip_tags')
return get_option('skip_tags');
}

function get_ignore_class(){
return get_option('ignore_class');
}

function get_process_class(){
return get_option('process_class');
}
2 changes: 2 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var default_options = {
display_dollar: true,
display_bracket: true,
display_custom: false,
ignore_class: false,
process_class: false,
skip_tags: ['script','noscript','style','textarea','pre','code']
};

Expand Down
37 changes: 36 additions & 1 deletion js/optionsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ function save_options() {
// White List Mode
set_option('white_list_mode', $('#chkWhiteListMode').is(':checked'));

// tex2jax Ignore Class
var ignore_class = $('#ignoreClass').val().trim();
if (!ignore_class) {
ignore_class = "tex2jax_ignore";
}
if ($('#chkIgnoreClass').is(':checked') && ignore_class) {
set_option('ignore_class', ignore_class);
} else {
set_option('ignore_class', false);
}
// tex2jax Process Class
var process_class = $('#processClass').val().trim();
if (!process_class) {
process_class = "tex2jax_process";
}
if ($('#chkProcessClass').is(':checked') && process_class) {
set_option('process_class', process_class);
} else {
set_option('process_class', false);
}

displayMessage('Options saved.');
}

Expand Down Expand Up @@ -100,6 +121,20 @@ function restore_options() {
text : site
}));
});

// tex2jax Ignore Class
var ignore_class = get_option('ignore_class');
if(ignore_class) {
$('#chkIgnoreClass').prop('checked', true);
$('#ignoreClass').val(ignore_class);
}

// tex2jax Process Class
var process_class = get_option('process_class');
if(process_class) {
$('#chkProcessClass').prop('checked', true);
$('#processClass').val(process_class);
}

// White List Mode
if (get_option('white_list_mode')) {
Expand Down Expand Up @@ -149,7 +184,7 @@ function clear_tags() {

function restore_default_tags() {
var default_tags = get_default_option('skip_tags');
clear_tags()
clear_tags();
$.each(default_tags, function(index, tag) {
$('#selTag').append($('<option>', {
value: tag,
Expand Down
4 changes: 3 additions & 1 deletion js/pageScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function config() {
tex2jax: {
inlineMath: JSON.parse(scriptNode.getAttribute('inlineMath')),
displayMath: JSON.parse(scriptNode.getAttribute('displayMath')),
skipTags: JSON.parse(scriptNode.getAttribute('skipTags'))
skipTags: JSON.parse(scriptNode.getAttribute('skipTags')),
ignoreClass: JSON.parse(scriptNode.getAttribute('ignoreClass')),
processClass: JSON.parse(scriptNode.getAttribute('processClass'))
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion js/texify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ chrome.runtime.sendMessage({method: 'shouldTeXify', host: location.host},
pageScript.setAttribute('inlineMath', JSON.stringify(inline_delimiters));
pageScript.setAttribute('displayMath', JSON.stringify(display_delimiters));
pageScript.setAttribute('skipTags', JSON.stringify(response.skip_tags));

pageScript.setAttribute('ignoreClass', JSON.stringify(response.ignore_class));
pageScript.setAttribute('processClass', JSON.stringify(response.process_class));

document.body.appendChild(mathjax);
document.body.appendChild(pageScript);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"short_name": "TeX Things",
"author": "emichael",
"description": "An extension which lets you enable LaTeX on any website",
"version": "1.1.4",
"version": "1.1.5",

"icons": {
"128": "img/icon128.png",
Expand Down
14 changes: 14 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ <h3><input type="checkbox" id="chkWhiteListMode">White List Mode</h3>
Otherwise, only domains in the list will <em>not</em> be typeset.
</p>

<h2>Ignored Classes Regex</h2>
<p class="optionInfo">
Add a class name below to mark elements whose contents should not be processed. <br>
Note that this is a regular expression, and so you need to be sure to quote any regexp special characters. The pattern is inserted into one that requires your pattern to match a complete word, so setting the pattern to "class2" will cause it to match an element with class="class1 class2 class3" but not class="myclass2". Note that you can assign several classes by separating them by the vertical line character (|). For instance, with the pattern set to "class1|class2" any element assigned a class of either class1 or class2 will be skipped.
</p>
<p><input type="checkbox" id="chkIgnoreClass">Ignore Class:<input type="text" id="ignoreClass" class="classBox"></p>

<h2>Processed Classes Regex</h2>
<p class="optionInfo">
Add a class name below to mark elements whose contents <i>should</i> be processed, even if they would have been ignored by "Ignored Classes Regex."<br>
Note that this is a regular expression, and so you need to be sure to quote any regexp special characters. The pattern is inserted into one that requires your pattern to match a complete word, so setting the pattern to "class2" will cause it to match an element with class="class1 class2 class3" but not class="myclass2". Note that you can assign several classes by separating them by the vertical line character (|). For instance, with the pattern set to "class1|class2" any element assigned a class of either class1 or class2 will be processed.
</p>
<p><input type="checkbox" id="chkProcessClass">Process Class:<input type="text" id="processClass" class="classBox"></p>

<button id="save">Save</button>

<script src="js/jquery.min.js"></script>
Expand Down

0 comments on commit 1345679

Please sign in to comment.