ucfopen / Obojobo

Next generation course content for your LMS. Easy for beginners, but powerful enough for researchers.
https://ucfopen.github.io/Obojobo-Docs/
GNU Affero General Public License v3.0
70 stars 34 forks source link

Prevent partial styles inside latex equations #1769

Open zachberry opened 3 years ago

zachberry commented 3 years ago

Related: #1272

The selected region was given a color of red in the visual editor:

Screen Shot 2021-04-09 at 2 45 26 PM

That resulted in this in the viewer, which shows an extra + b

Screen Shot 2021-04-09 at 2 45 31 PM

The resulting XML:

<t indent="0">Here is the equa<color text="#990000">tion y = mx + b: </color><latex><color text="#990000">y = mx</color> + b</latex>. That was the equation y = mx + b.</t>

And JSON:

"textGroup": [
    {
        "data": {
            "indent": "0"
        },
        "text": {
            "value": "Here is the equation y = mx + b: y = mx + b. That was the equation y = mx + b.",
            "styleList": [
                {
                    "end": 33,
                    "data": {
                        "text": "#990000"
                    },
                    "type": "color",
                    "start": 16
                },
                {
                    "end": 43,
                    "data": {},
                    "type": "_latex",
                    "start": 33
                },
                {
                    "end": 39,
                    "data": {
                        "text": "#990000"
                    },
                    "type": "color",
                    "start": 33
                }
            ]
        }
    }
]

Note that colored inline equations do work if the whole equation is selected:

image

<t indent="0">Here is the equation y = mx + b: <latex><color text="#990000">y = mx + b</color></latex>. That was the equation y = mx + b.</t>

We have the same issue when bolding text, and I assume with all the other styles although I didn't exhaustively test every one.

I think there's two possible solutions:

  1. Don't allow any color styles inside inline latex content.
  2. If a portion of latex content is styled, force the entire latex content to be styled instead.

I'm leaning towards 2 being the better option, however we'd need a modular way to transform styles - once the author sets latex content to a style we'd need to be able to expand the colored area to include all of the latex content. It would probably also be good to enforce that in StyleableText / StyleList, so if an author incorrectly styled a portion of latex content in XML/JSON the style would automatically be expanded to the latex (I don't think we'd want to expand the selection though, unless necessary). That would want to be a one-time operation before rending text content in the viewer, so it doesn't have to calculate the expansion on every render, but we also may want to hold off doing it until the render is needed.

Additionally, colors should probably be visible in the editor when applied to latex content. Currently it always shows as blue text.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep our backlog under control, but we thank you for your contributions.