Skip to content

Commit

Permalink
Merge pull request #873 from adam-p/new-latex
Browse files Browse the repository at this point in the history
Switch LaTeX renderer to CodeCogs
  • Loading branch information
adam-p authored Nov 9, 2024
2 parents 4bfd574 + 9628a6d commit 0f8fecb
Show file tree
Hide file tree
Showing 34 changed files with 3,339 additions and 3,115 deletions.
520 changes: 267 additions & 253 deletions src/_locales/de/messages.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@
"message": "<strong>Privacy Issues:</strong>",
"description": "heading for warnings about TeX math privacy concerns"
},
"options_page__tex_math_privacy_issue_1": {
"message": "To generate the image for the formula, a request is sent to Google. That effectively means that you are sharing your formula with Google. It also means that recipients of your message will be making a request to Google to have the image rendered.",
"options_page__tex_math_codecogs_privacy_issue_1": {
"message": "To generate the image for the formula, a request is sent to CodeCogs. That effectively means that you are sharing your formula with CodeCogs. It also means that recipients of your message will be making a request to CodeCogs to have the image rendered.",
"description": "one of the TeX math privacy concerns"
},
"options_page__tex_math_privacy_issue_2": {
Expand All @@ -220,11 +220,11 @@
"message": "If this feature is enabled, text between dollar signs — <code>$$</code> — will be interpreted as mathematical formulae. For example, <code>$$\\Delta$$</code> would be rendered as a delta symbol.",
"description": "Note: Double dollar signs ($$) are necessary to get a single dollar sign."
},
"options_page__tex_math_customization_2": {
"message": "For render customization options, see the <a href=\"https://developers.google.com/chart/infographics/docs/formulas\" target=\"_blank\">Google Charts documentation</a> for this service."
"options_page__tex_math_codecogs_customization_2": {
"message": "For render customization options, see the <a href=\"https://editor.codecogs.com/docs/4-LaTeX_rendering.php\" target=\"_blank\">CodeCogs documentation</a> for this service."
},
"options_page__tex_math_customization_3": {
"message": "A good resource for creating TeX formulae is the <a href=\"https://www.codecogs.com/latex/about.php\" target=\"_blank\">CodeCogs Equation Editor</a>."
"message": "A good resource for creating TeX formulae is the <a href=\"https://editor.codecogs.com/\" target=\"_blank\">CodeCogs Equation Editor</a>."
},
"options_page__tex_math_customization_4": {
"message": "Formulae are rendered to images, so email recipients will have to enable images to be shown to see the rendering."
Expand Down
519 changes: 266 additions & 253 deletions src/_locales/es/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/fr/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/it/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/ja/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/ko/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/pl/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/pt_BR/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/ru/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/tr/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/zh_CN/messages.json

Large diffs are not rendered by default.

519 changes: 266 additions & 253 deletions src/_locales/zh_TW/messages.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/common/options-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (typeof(Utils) === 'undefined' && typeof(Components) !== 'undefined') {
// Common defaults
var DEFAULTS = {
'math-enabled': true,
'math-value': '<img src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">',
'math-value': '<img src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;{urlmathcode}" alt="{mathcode}">',
'hotkey': { shiftKey: false, ctrlKey: true, altKey: true, key: 'M' },
'forgot-to-render-check-enabled': false,
'header-anchors-enabled': false,
Expand Down Expand Up @@ -50,6 +50,7 @@ var DEFAULTS = {

var ChromeOptionsStore = {


// The options object will be passed to `callback`
get: function(callback) {
var that = this;
Expand Down Expand Up @@ -500,6 +501,14 @@ if (!this.OptionsStore) {
this.OptionsStore._fillDefaults = function(prefsObj, callback) {
var that = this;

// Upgrade the object, if necessary.
// Motivation: Our default for the LaTeX renderer used to be Google Charts API. Google
// discontinued the service and we switched the default to CodeCogs, but because it was
// the default, it will be set in many users' OptionsStore. We need to forcibly replace it.
if (typeof prefsObj['math-value'] === 'string' && prefsObj['math-value'].indexOf('chart.googleapis.com') >= 0) {
prefsObj['math-value'] = that.defaults['math-value'];
}

var key, allKeys = [];
for (key in that.defaults) {
if (that.defaults.hasOwnProperty(key)) {
Expand Down
10 changes: 5 additions & 5 deletions src/common/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ <h1>
<p>
<span data-i18n="tex_math_privacy_heading"><strong>Privacy Issues:</strong></span>
<ul>
<li data-i18n="tex_math_privacy_issue_1">
To generate the image for the formula, a request is sent to Google. That effectively means that you are sharing your formula with Google. It also means that recipients of your message will be making a request to Google to have the image rendered.
<li data-i18n="tex_math_codecogs_privacy_issue_1">
To generate the image for the formula, a request is sent to CodeCogs. That effectively means that you are sharing your formula with CodeCogs. It also means that recipients of your message will be making a request to CodeCogs to have the image rendered.
</li>
<li data-i18n="tex_math_privacy_issue_2">
If you customize the formula rendering tag, you should use a secure (https://) path. Not all rendering services provide a secure option.
Expand All @@ -520,11 +520,11 @@ <h1>
<li data-i18n="tex_math_customization_1">
If this feature is enabled, text between dollar signs — <code>$</code> — will be interpreted as mathematical formulae. For example, <code>$\Delta$</code> would be rendered as a delta symbol.
</li>
<li data-i18n="tex_math_customization_2">
For render customization options, see the <a href="https://developers.google.com/chart/infographics/docs/formulas" target="_blank">Google Charts documentation</a> for this service.
<li data-i18n="tex_math_codecogs_customization_2">
For render customization options, see the <a href="https://editor.codecogs.com/docs/4-LaTeX_rendering.php" target="_blank">CodeCogs documentation</a> for this service.
</li>
<li data-i18n="tex_math_customization_3">
A good resource for creating TeX formulae is the <a href="https://www.codecogs.com/latex/about.php" target="_blank">CodeCogs Equation Editor</a>.
A good resource for creating TeX formulae is the <a href="https://editor.codecogs.com/" target="_blank">CodeCogs Equation Editor</a>.
</li>
<li data-i18n="tex_math_customization_4">
Formulae are rendered to images, so email recipients will have to enable images to be shown to see the rendering.
Expand Down
34 changes: 17 additions & 17 deletions src/common/test/markdown-render-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Markdown-Render', function() {
// Test issue #57: https://github.com/adam-p/markdown-here/issues/57
it('should add the schema to links missing it', function() {
var md = 'asdf [aaa](bbb) asdf [ccc](ftp://ddd) asdf';
var target = '<p>asdf <a href="http://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n';
var target = '<p>asdf <a href="https://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n';
expect(MarkdownRender.markdownRender(md, userprefs, marked, hljs)).to.equal(target);
});

Expand Down Expand Up @@ -85,17 +85,17 @@ describe('Markdown-Render', function() {
// https://github.com/adam-p/markdown-here/issues/84
it('should render single-character math formulae', function() {
userprefs = {
'math-value': '<img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">',
'math-value': '<img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;{urlmathcode}" alt="{mathcode}">',
'math-enabled': true
};

var md = '$x$';
var target = '<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=x" alt="x"></p>\n';
var target = '<p><img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;x" alt="x"></p>\n';
expect(MarkdownRender.markdownRender(md, userprefs, marked, hljs)).to.equal(target);

// Make sure we haven't broken multi-character forumlae
md = '$xx$';
target = '<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=xx" alt="xx"></p>\n';
target = '<p><img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;xx" alt="xx"></p>\n';
expect(MarkdownRender.markdownRender(md, userprefs, marked, hljs)).to.equal(target);
});

Expand Down Expand Up @@ -241,36 +241,36 @@ describe('Markdown-Render', function() {
'<p>asdf <a href="http://www.aaa.com">bbb</a> asdf</p>\n']);

tests.push(['<a href="aaa">bbb</a>',
'<p><a href="http://aaa">bbb</a></p>\n']);
'<p><a href="https://aaa">bbb</a></p>\n']);

tests.push(['[xxx](yyy) <a href="aaa">bbb</a>',
'<p><a href="http://yyy">xxx</a> <a href="http://aaa">bbb</a></p>\n']);
'<p><a href="https://yyy">xxx</a> <a href="https://aaa">bbb</a></p>\n']);

tests.push(['asdf (<a href="aaa">bbb</a>)',
'<p>asdf (<a href="http://aaa">bbb</a>)</p>\n']);
'<p>asdf (<a href="https://aaa">bbb</a>)</p>\n']);

// Begin tests where the link should *not* be converted.
// Note that some tests are affected by issue #57: MD links should automatically add scheme

tests.push(['asdf [yyy](<a href="http://www.aaa.com">bbb</a>) asdf',
'<p>asdf <a href="http://bbb">yyy</a> asdf</p>\n']);
'<p>asdf <a href="https://bbb">yyy</a> asdf</p>\n']);

tests.push(['asdf [<a href="http://www.aaa.com">bbb</a>](ccc) asdf',
'<p>asdf <a href="http://ccc">bbb</a> asdf</p>\n']);
'<p>asdf <a href="https://ccc">bbb</a> asdf</p>\n']);

tests.push(['[yyy](<a href="http://www.aaa.com">bbb</a>)',
'<p><a href="http://bbb">yyy</a></p>\n']);
'<p><a href="https://bbb">yyy</a></p>\n']);

tests.push(['[yyy]( <a href="http://www.aaa.com">bbb</a>)',
'<p><a href="http://bbb">yyy</a></p>\n']);
'<p><a href="https://bbb">yyy</a></p>\n']);

tests.push(['asdf [qwer <a href="http://www.aaa.com">bbb</a>](ccc) asdf',
'<p>asdf <a href="http://ccc">qwer bbb</a> asdf</p>\n']);
'<p>asdf <a href="https://ccc">qwer bbb</a> asdf</p>\n']);

// Begin mixed tests

tests.push(['asdf [aaa](bbb) asdf <a href="http://www.aaa.com">bbb</a> asdf [yyy](<a href="http://www.aaa.com">bbb</a>) asdf',
'<p>asdf <a href="http://bbb">aaa</a> asdf <a href="http://www.aaa.com">bbb</a> asdf <a href="http://bbb">yyy</a> asdf</p>\n']);
'<p>asdf <a href="https://bbb">aaa</a> asdf <a href="http://www.aaa.com">bbb</a> asdf <a href="https://bbb">yyy</a> asdf</p>\n']);

// Begin tests that don't work quite right

Expand All @@ -288,7 +288,7 @@ describe('Markdown-Render', function() {
// Test issue #57: https://github.com/adam-p/markdown-here/issues/57
it('should add the schema to links missing it', function() {
var md = 'asdf [aaa](bbb) asdf [ccc](ftp://ddd) asdf';
var target = '<p>asdf <a href="http://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n';
var target = '<p>asdf <a href="https://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n';
expect(fullRender(md)).to.equal(target);
});

Expand Down Expand Up @@ -320,17 +320,17 @@ describe('Markdown-Render', function() {
// https://github.com/adam-p/markdown-here/issues/84
it('should render single-character math formulae', function() {
userprefs = {
'math-value': '<img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">',
'math-value': '<img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;{urlmathcode}" alt="{mathcode}">',
'math-enabled': true
};

var md = '$x$';
var target = '<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=x" alt="x"></p>\n';
var target = '<p><img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;x" alt="x"></p>\n';
expect(fullRender(md)).to.equal(target);

// Make sure we haven't broken multi-character forumlae
md = '$xx$';
target = '<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=xx" alt="xx"></p>\n';
target = '<p><img class="mdh-math" src="https://latex.codecogs.com/png.image?\\dpi{120}\\inline&space;xx" alt="xx"></p>\n';
expect(fullRender(md)).to.equal(target);
});

Expand Down
Loading

0 comments on commit 0f8fecb

Please sign in to comment.