Make input escaping optional. Fixes #11

This commit is contained in:
Eric Wood 2017-01-04 18:24:24 -05:00
parent 6495006a0f
commit d01d0c3cb6
No known key found for this signature in database
GPG Key ID: 645B0CD779EED3B5
2 changed files with 12 additions and 4 deletions

View File

@ -12,6 +12,8 @@
latexEnvironment: 'array', latexEnvironment: 'array',
latexEscape: function(text) { latexEscape: function(text) {
if(!$('#escape').is(':checked')) return text;
var escapeRegExpr = function(str) { var escapeRegExpr = function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}; };
@ -63,7 +65,7 @@
} }
latex += "\\end{" + excelParser.latexEnvironment + "}\n"; latex += "\\end{" + excelParser.latexEnvironment + "}\n";
return latex; return latex;
}, },
@ -110,7 +112,7 @@
// read the workbook meta data to get the names and crap // read the workbook meta data to get the names and crap
workbookMeta.getData(new zip.TextWriter(), function(text) { workbookMeta.getData(new zip.TextWriter(), function(text) {
var doc = $(text); var doc = $(text);
// extract the names of the workbooks and their IDs for use later on... // extract the names of the workbooks and their IDs for use later on...
$.each(doc.find('sheets sheet'), function(i, tag) { $.each(doc.find('sheets sheet'), function(i, tag) {
tag = $(tag); tag = $(tag);
@ -125,12 +127,12 @@
$.each(sheets, function(_, sheet) { $.each(sheets, function(_, sheet) {
// the ID of the spreadsheet can only be found in the filename apparently :P // the ID of the spreadsheet can only be found in the filename apparently :P
var id = sheet.filename.match(/(\d)\.xml/)[1]; var id = sheet.filename.match(/(\d)\.xml/)[1];
sheet.getData(new zip.TextWriter(), function(text) { sheet.getData(new zip.TextWriter(), function(text) {
var table = excelParser.processSheet(text, stringTable); var table = excelParser.processSheet(text, stringTable);
var latex = excelParser.toLatex(table); var latex = excelParser.toLatex(table);
latexOutput[id] = latex; latexOutput[id] = latex;
// I apologize for the hack :( // I apologize for the hack :(
if(id === '1') { if(id === '1') {
excelParser.showOutput(1); excelParser.showOutput(1);

View File

@ -29,6 +29,12 @@
<select id="workbook" name="workbook"></select> <select id="workbook" name="workbook"></select>
<textarea id="latex-output" readonly="readonly" onclick="this.select();"></textarea> <textarea id="latex-output" readonly="readonly" onclick="this.select();"></textarea>
<div class="settings">
<input type="checkbox" name="escape" id="escape" checked="checked">
<label for="escape">Escape input text</label>
</div>
<p>Mostly untested, so if you find a bug or have a feature request, <a href="https://github.com/eric-wood/excel2latex/issues">let me know!</a> <p>Mostly untested, so if you find a bug or have a feature request, <a href="https://github.com/eric-wood/excel2latex/issues">let me know!</a>
<p class="disclaimer">Note: this only works with .xlsx files. That means .xls files will <b>not</b> work.</p> <p class="disclaimer">Note: this only works with .xlsx files. That means .xls files will <b>not</b> work.</p>
<p>Formatting from the Excel document won't be preserved, only the text will be extracted.</p> <p>Formatting from the Excel document won't be preserved, only the text will be extracted.</p>