-
Notifications
You must be signed in to change notification settings - Fork 630
Fixes #5809: Use view text color and force block rendering to fix math fraction visibility in dark mode #6283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikhilkumarpanigrahi
wants to merge
7
commits into
oppia:develop
Choose a base branch
from
nikhilkumarpanigrahi:fix-math-fraction-visibility
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74b3ba5
Use view text color and force block rendering to fix fraction visibility
nikhilkumarpanigrahi 93e3969
Update tests and build config for math fraction visibility fix
nikhilkumarpanigrahi a62b460
Address Copilot review: fix variable name and decouple color test fro…
nikhilkumarpanigrahi d2a9216
Remove unrelated .bazelrc and .gitignore changes from fraction fix PR
nikhilkumarpanigrahi aff511b
Fix ktlint line-length violations in MathTagHandlerTest
nikhilkumarpanigrahi 54f0cab
Fix HtmlParserTest inline math test to use non-frac expression
nikhilkumarpanigrahi 0bebb69
Fix HtmlParserTest: remove extra backslash from x^2 latex markup
nikhilkumarpanigrahi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,11 @@ private const val MATH_WITHOUT_FILENAME_MARKUP = | |
| "<oppia-noninteractive-math math_content-with-value=\"{&quot;raw_latex&quot;" + | ||
| ":&quot;\\\\frac{2}{5}&quot;}\"></oppia-noninteractive-math>" | ||
|
|
||
| // A non-\frac expression so these tests exercise the inline code-path (not block-forced by \frac). | ||
| private const val MATH_WITHOUT_FILENAME_INLINE_MARKUP = | ||
| "<oppia-noninteractive-math math_content-with-value=\"{&quot;raw_latex&quot;" + | ||
| ":&quot;x^2&quot;}\"></oppia-noninteractive-math>" | ||
|
|
||
| private const val MATH_WITHOUT_FILENAME_RENDER_TYPE_INLINE_MARKUP = | ||
| "<oppia-noninteractive-math render-type=\"inline\"" + | ||
| " math_content-with-value=\"{&quot;raw_latex&quot;" + | ||
|
|
@@ -117,7 +122,7 @@ class MathTagHandlerTest { | |
| fun testParseHtml_withMathMarkup_cachingOn_imageSpanHasCorrectMetrics() { | ||
|
|
||
| val parsedHtml = CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_MARKUP, | ||
| html = MATH_WITHOUT_FILENAME_INLINE_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = tagHandlersWithCachedMathSupport | ||
| ) | ||
|
|
@@ -142,7 +147,7 @@ class MathTagHandlerTest { | |
| fun testParseHtml_withMathMarkup_cachingOn_drawsAtCorrectVerticalPosition() { | ||
|
|
||
| val parsedHtml = CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_MARKUP, | ||
| html = MATH_WITHOUT_FILENAME_INLINE_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = tagHandlersWithCachedMathSupport | ||
| ) | ||
|
|
@@ -306,43 +311,43 @@ class MathTagHandlerTest { | |
| } | ||
|
|
||
| @Test | ||
| fun testParseHtml_withMathMarkup_missingFilename_includesCachedInlineLatexImageSpan() { | ||
| fun testParseHtml_withMathMarkup_missingFilename_withFrac_includesCachedBlockLatexImageSpan() { | ||
| val parsedHtml = | ||
| CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = tagHandlersWithCachedMathSupport | ||
| ) | ||
|
|
||
| // The image span is a cached bitmap loaded from LaTeX. | ||
| // \frac expressions are always rendered in block mode for the horizontal fraction bar. | ||
| val imageSpans = parsedHtml.getSpansFromWholeString(ImageSpan::class) | ||
| assertThat(imageSpans).hasLength(1) | ||
| verify(mockImageRetriever)!!.loadMathDrawable( | ||
| capture(stringCaptor), capture(floatCaptor), | ||
| capture(colorCaptor), capture(retrieverTypeCaptor) | ||
| ) | ||
| assertThat(stringCaptor.value).isEqualTo("\\frac{2}{5}") | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.INLINE_TEXT_IMAGE) | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.BLOCK_IMAGE) | ||
| } | ||
|
|
||
| @Test | ||
| fun testParseHtml_withMathMarkup_missingFilename_inlineMode_includesCachedInlineLatexImageSpan() { | ||
| fun testParseHtml_withMathMarkup_missingFilename_inlineMode_includesCachedBlockLatexImageSpan() { | ||
| val parsedHtml = | ||
| CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_RENDER_TYPE_INLINE_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = tagHandlersWithCachedMathSupport | ||
| ) | ||
|
|
||
| // The image span is a cached bitmap loaded from LaTeX. | ||
| // \frac overrides even an explicit inline render-type to ensure the horizontal bar is visible. | ||
| val imageSpans = parsedHtml.getSpansFromWholeString(ImageSpan::class) | ||
| assertThat(imageSpans).hasLength(1) | ||
| verify(mockImageRetriever)!!.loadMathDrawable( | ||
| capture(stringCaptor), capture(floatCaptor), | ||
| capture(colorCaptor), capture(retrieverTypeCaptor) | ||
| ) | ||
| assertThat(stringCaptor.value).isEqualTo("\\frac{2}{5}") | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.INLINE_TEXT_IMAGE) | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.BLOCK_IMAGE) | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -460,7 +465,7 @@ class MathTagHandlerTest { | |
| capture(colorCaptor), capture(retrieverTypeCaptor) | ||
| ) | ||
| assertThat(stringCaptor.value).isEqualTo("\\frac{2}{5}") | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.INLINE_TEXT_IMAGE) | ||
| assertThat(retrieverTypeCaptor.value).isEqualTo(ImageRetriever.Type.BLOCK_IMAGE) | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -481,7 +486,7 @@ class MathTagHandlerTest { | |
| .containsExactly("\\frac{3}{8}", "\\frac{2}{5}") | ||
| .inOrder() | ||
| assertThat(retrieverTypeCaptor.allValues) | ||
| .containsExactly(ImageRetriever.Type.INLINE_TEXT_IMAGE, ImageRetriever.Type.INLINE_TEXT_IMAGE) | ||
| .containsExactly(ImageRetriever.Type.BLOCK_IMAGE, ImageRetriever.Type.BLOCK_IMAGE) | ||
| .inOrder() | ||
| } | ||
|
|
||
|
|
@@ -531,14 +536,58 @@ class MathTagHandlerTest { | |
| assertThat(parsedHtmlStr).contains(" and ") | ||
| } | ||
|
|
||
| private fun createMathTagHandler(cacheLatexRendering: Boolean): MathTagHandler { | ||
| @Test | ||
| fun testParseHtml_withMathMarkup_cachingOff_withProvidedEquationColor_usesProvidedColor() { | ||
| val customColor = Color.MAGENTA | ||
| val parsedHtml = | ||
| CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = mapOf( | ||
| CUSTOM_MATH_TAG to createMathTagHandler( | ||
| cacheLatexRendering = false, | ||
| equationColor = customColor | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| val mathExpressionSpans = parsedHtml.getSpansFromWholeString(MathExpressionSpan::class) | ||
| assertThat(mathExpressionSpans[0].equationColor).isEqualTo(customColor) | ||
| } | ||
|
|
||
| @Test | ||
| fun testParseHtml_withMathMarkup_cachingOn_withProvidedEquationColor_usesProvidedColor() { | ||
| val customColor = Color.CYAN | ||
| CustomHtmlContentHandler.fromHtml( | ||
| html = MATH_WITHOUT_FILENAME_INLINE_MARKUP, | ||
| imageRetriever = mockImageRetriever, | ||
| customTagHandlers = mapOf( | ||
| CUSTOM_MATH_TAG to createMathTagHandler( | ||
| cacheLatexRendering = true, | ||
| equationColor = customColor | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| verify(mockImageRetriever)!!.loadMathDrawable( | ||
| capture(stringCaptor), capture(floatCaptor), | ||
| capture(colorCaptor), capture(retrieverTypeCaptor) | ||
| ) | ||
| assertThat(colorCaptor.value).isEqualTo(customColor) | ||
| } | ||
|
Comment on lines
+559
to
+577
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — switched the fixture to |
||
|
|
||
| private fun createMathTagHandler( | ||
| cacheLatexRendering: Boolean, | ||
| equationColor: Int? = null | ||
| ): MathTagHandler { | ||
| // Pick an arbitrary line height since rendering doesn't actually happen in tests. | ||
| return MathTagHandler( | ||
| consoleLogger, | ||
| context.assets, | ||
| lineHeight = 10.0f, | ||
| cacheLatexRendering, | ||
| application = context.applicationContext as Application | ||
| application = context.applicationContext as Application, | ||
| equationColor = equationColor | ||
| ) | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fully sure about forcing every
\fracexpression into block mode here. This seems to overriderender-type="inline"for all fractions across the app. From checking the KotliTeX fraction code,\fracalready creates a fraction line, so I am not sure the horizontal bar only exists in block/display mode.Could you please share a small before/after screenshot showing that inline
\fracloses the horizontal bar? This feels separate from the dark-mode contrast issue in #5809, and it may change inline lesson layout in other places.Also, the old inline
\fractest was changed tox^2, so we no longer have coverage for the explicit inline fraction case. Can we avoid this override, or add proof/tests that this behavior is intended? PTAL.