1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-02-24 09:33:19 +01:00
BezierInfo-2/tools/cleanup.js

28 lines
810 B
JavaScript
Raw Normal View History

2016-01-22 17:43:40 -08:00
module.exports = function cleanUp(latex) {
2017-09-18 20:39:25 -07:00
// strip any \[ and \], which is a block-level LaTeX markup indicator for MathJax:
2016-01-22 17:43:40 -08:00
latex = latex.replace(/^'/,'').replace(/'$/,'').replace('\\[','').replace('\\]','');
2017-02-27 11:01:13 -08:00
// wrap some known functor words in italics markup
['Bézier'].forEach(term => {
latex = latex.replace(new RegExp(term, 'g'), '\\textit{' + term + '}');
});
2016-01-22 17:43:40 -08:00
// also unindent the LaTeX.
var indent = false;
2017-09-18 20:40:24 -07:00
var lines = latex.split('\n').filter(line => !!line.trim());
2016-01-22 17:43:40 -08:00
var clean = function(line, idx) {
2017-09-18 20:41:13 -07:00
if (!indent) {
var matched = line.match(/^(\s+)/);
if (matched) {
indent = matched[0];
2016-01-22 17:43:40 -08:00
}
}
2017-09-18 20:41:13 -07:00
if (indent) {
lines[idx] = line.replace(indent,'').trim();
}
2016-01-22 17:43:40 -08:00
}
lines.forEach(clean);
latex = lines.join('\n');
return latex;
};