codewars / codewars.com

Issue tracker for Codewars
https://www.codewars.com
BSD 2-Clause "Simplified" License
2.09k stars 220 forks source link

Katex renderer duplicates the expressions in description preview and during some copy/paste operations #2752

Open Blind4Basics opened 2 years ago

Blind4Basics commented 2 years ago

Describe the bugs

Not sure if it's old or new, but the renderer is litterally acting, here:

NOTE:

once the fork is published, the description looks fine (but cause the copy/paste troubles)

┆Issue is synchronized with this Clickup by Unito

kazk commented 2 years ago

The first one is caused by katex.min.css not included on that page, so the preview is showing elements that's supposed to be hidden by it.

I think the second one has something to do with KaTeX outputting HTML and MathML (for accessibility). Selecting a paragraph copies both text? Not sure about this one.

Blind4Basics commented 2 years ago

Selecting a paragraph copies both text?

from the same kata/description, copying in the trainer:

// copying the full line (which is a §):

The starting point A0(x0,y0) A_0 (x_0, y_0) A0​(x0​,y0​) is known as well as the slope to the curve at A0 A_0 A0​ and then the tangent line at A0 A_0 A0​ .

// copying a full § with extra text before and after:

−2x.

For each xk x_k xk​ we are able to calculate the yk y_k yk​ as well as the values zk z_k zk​ of the exact solution.

Our task

It looks like the $ "tags" were replaced by the expression itself (makes me think to regex matches)

kazk commented 2 years ago

It shouldn't have anything to do with the original input text because only the text inside $ and math block are passed to KaTeX.

Look at the HTML it generated. It should have mathml and some spans. I thought selecting a paragraph selects both of them and the text content is copied.

kazk commented 2 years ago

Probably https://github.com/KaTeX/KaTeX/issues/645

kazk commented 2 years ago

The first one should be fixed.

kazk commented 2 years ago

Using the copy-tex extension should fix the second issue. But it doesn't work properly on Codewars because we use DOMPurify to sanitize the generated HTML, and <annotation> element used by that extension is filtered because it can be unsafe (https://github.com/cure53/DOMPurify/issues/673).

Not sure what can be done.

Blind4Basics commented 2 years ago

as long as the vizual is ok, I guess it can stay like this...