Skip to content

Commit

Permalink
fix: #399 Katex - backslash disappears of attr
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Oct 29, 2020
1 parent fe05240 commit 0acbe54
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/plugins/dialog/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default {

_renderer: function (exp) {
const katex = this.context.option.katex;
return katex.src.renderToString(exp, katex.options);
return katex.src.renderToString(exp.replace(/\\\\\\/g, "\\"), katex.options);
},

_renderMathExp: function (contextMath, e) {
Expand All @@ -157,7 +157,7 @@ export default {
if (!katexEl) return false;
katexEl.className = '__se__katex ' + katexEl.className;
katexEl.setAttribute('contenteditable', false);
katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp));
katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp).replace(/\\/g, '\\\\\\'));
katexEl.setAttribute('data-font-size', contextMath.fontSizeElement.value);
katexEl.style.fontSize = contextMath.fontSizeElement.value;

Expand Down Expand Up @@ -229,7 +229,7 @@ export default {
const exp = this.util.HTMLDecoder(contextMath._mathExp.getAttribute('data-exp'));
const fontSize = contextMath._mathExp.getAttribute('data-font-size') || '1em';
this.context.dialog.updateModal = true;
contextMath.focusElement.value = exp;
contextMath.focusElement.value = exp.replace(/\\\\\\/g, "\\");
contextMath.fontSizeElement.value = fontSize;
contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, exp);
contextMath.previewElement.style.fontSize = fontSize;
Expand All @@ -254,7 +254,7 @@ export default {
e.preventDefault();

if (/update/.test(command)) {
this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp'));
this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp')).replace(/\\\\\\/g, "\\");
this.plugins.dialog.open.call(this, 'math', true);
} else {
/** delete */
Expand Down

0 comments on commit 0acbe54

Please sign in to comment.