Skip to content

Commit

Permalink
fixup! ✨(forum) enables latext mathematical syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
carofun committed Dec 21, 2022
1 parent ba213b9 commit 63f1bd6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/ashley/editor/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def inlinetex(props):
"""
Decorator for the `INLINETEX` entity in Draft.js ContentState.
"""
return DOM.create_element("span", {"class": "latex-inline"}, props.get("tex", None))
return DOM.create_element(
"span", {"class": "ashley-custom-latex-inline"}, props.get("tex", None)
)


def render_children(props):
Expand All @@ -110,7 +112,7 @@ def render_children(props):
if props.get("block").get("data").get("type") == "TEXBLOCK":
return DOM.create_element(
"span",
{"class": "latex-display"},
{"class": "ashley-custom-latex-display"},
props.get("block").get("data").get("tex", None),
)

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/utils/latex.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import katex from 'katex';

export const renderLatex = () => {
document.querySelectorAll('[class^=latex]').forEach((math) => {
document.querySelectorAll('[class^=ashley-custom-latex]').forEach((math) => {
if (math.textContent) {
math.innerHTML = katex.renderToString(math.textContent, {
displayMode: math.classList.contains('latex-display'),
displayMode: math.classList.contains('ashley-custom-latex-display'),
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_custom_decorator_inlinetex_ok(self):
tex = "\left.\frac{x^3}{3}\right|_0^1" # noqa: W605
self.assertEqual(
DOM.render(DOM.create_element(inlinetex, {"tex": tex})),
f'<span class="latex-inline">{tex}</span>',
f'<span class="ashley-custom-latex-inline">{tex}</span>',
)

def test_custom_decorator_inlinetex_empty(self):
Expand All @@ -25,7 +25,7 @@ def test_custom_decorator_inlinetex_empty(self):
"""
self.assertEqual(
DOM.render(DOM.create_element(inlinetex, {"tex": ""})),
'<span class="latex-inline"></span>',
'<span class="ashley-custom-latex-inline"></span>',
)

def test_custom_decorator_inlinetex_no_maths(self):
Expand All @@ -35,7 +35,7 @@ def test_custom_decorator_inlinetex_no_maths(self):
"""
self.assertEqual(
DOM.render(DOM.create_element(inlinetex, {"tex": "a common string"})),
'<span class="latex-inline">a common string</span>',
'<span class="ashley-custom-latex-inline">a common string</span>',
)

def test_custom_decorator_displaytex_ok(self):
Expand All @@ -59,7 +59,7 @@ def test_custom_decorator_displaytex_ok(self):
},
)
),
f'<span class="latex-display">{tex}</span>',
f'<span class="ashley-custom-latex-display">{tex}</span>',
)

def test_custom_decorator_displaytex_empty(self):
Expand All @@ -81,7 +81,7 @@ def test_custom_decorator_displaytex_empty(self):
},
)
),
'<span class="latex-display"></span>',
'<span class="ashley-custom-latex-display"></span>',
)

def test_custom_decorator_displaytex_no_maths(self):
Expand All @@ -103,7 +103,7 @@ def test_custom_decorator_displaytex_no_maths(self):
},
)
),
'<span class="latex-display">a common string</span>',
'<span class="ashley-custom-latex-display">a common string</span>',
)

def test_custom_decorator_displaytex_no_malformed(self):
Expand All @@ -125,5 +125,5 @@ def test_custom_decorator_displaytex_no_malformed(self):
},
)
),
'<span class="latex-display"></span>',
'<span class="ashley-custom-latex-display"></span>',
)

0 comments on commit 63f1bd6

Please sign in to comment.