Skip to content

Commit

Permalink
refactor: handle some more formats
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 23, 2024
1 parent 666d272 commit 71550be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/content/search/plain_text_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class PlainTextMath:
("\\right", ""),
)
regex_replacements = (
# Makes text bold, so not required in plain text.
(re.compile(r'\\mathbf{(.*?)}'), r"\1"),
(re.compile(r'{\\bf (.*?)}'), r"\1"),
)

def _fraction_handler(self, equation: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ def test_mathjax_plain_text_conversion_for_search(self):
" Greek letters: [mathjaxinline] \\alpha [/mathjaxinline] [mathjaxinline] \\beta [/mathjaxinline] [mathjaxinline] \\gamma [/mathjaxinline] |||"
" Subscripted variables: [mathjaxinline] x_i [/mathjaxinline] [mathjaxinline] y_j [/mathjaxinline] |||"
" Superscripted variables: [mathjaxinline] x^{i} [/mathjaxinline] |||"
" Not supported: \\( \\begin{bmatrix} 1 & 0 \\ 0 & 1 \\end{bmatrix} = I \\)"
" Not supported: \\( \\begin{bmatrix} 1 & 0 \\ 0 & 1 \\end{bmatrix} = I \\) |||"
" Bold text: \\( {\\bf a} \\cdot {\\bf b} = |{\\bf a}| |{\\bf b}| \\cos(\\theta) \\) |||"
" Bold text: \\( \\frac{\\sqrt{\\mathbf{2}+3}}{\\sqrt{4}} \\)"
),
)
# pylint: enable=line-too-long
Expand Down Expand Up @@ -551,6 +553,8 @@ def test_mathjax_plain_text_conversion_for_search(self):
'Subscripted variables: xᵢ yⱼ',
'Superscripted variables: xⁱ',
'Not supported: \\begin{bmatrix} 1 & 0 \\ 0 & 1 \\end{bmatrix} = I',
'Bold text: a ⋅ b = |a| |b| cos(θ)',
'Bold text: (√{2+3}/√{4})',
]
eqns = doc['description'].split('|||')
for i, eqn in enumerate(eqns):
Expand Down

0 comments on commit 71550be

Please sign in to comment.