From 71550becb6a0c33907b21fb5e4491a424ba4ab8e Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Mon, 23 Dec 2024 20:50:09 +0530 Subject: [PATCH] refactor: handle some more formats --- openedx/core/djangoapps/content/search/plain_text_math.py | 2 ++ .../core/djangoapps/content/search/tests/test_documents.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content/search/plain_text_math.py b/openedx/core/djangoapps/content/search/plain_text_math.py index c896815b7ac4..eb9579986926 100644 --- a/openedx/core/djangoapps/content/search/plain_text_math.py +++ b/openedx/core/djangoapps/content/search/plain_text_math.py @@ -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: diff --git a/openedx/core/djangoapps/content/search/tests/test_documents.py b/openedx/core/djangoapps/content/search/tests/test_documents.py index d8d3ccd28fcb..2a4f0a2032a1 100644 --- a/openedx/core/djangoapps/content/search/tests/test_documents.py +++ b/openedx/core/djangoapps/content/search/tests/test_documents.py @@ -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 @@ -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):