Skip to content
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

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

Open
1 of 2 tasks
Blind4Basics opened this issue Jul 25, 2022 · 7 comments

Comments

@Blind4Basics
Copy link

Blind4Basics commented Jul 25, 2022

Describe the bugs

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

  • when previewing a description (I'm forking a kata, in the capture below) all katex expressions are tripled. This occurs with any kind of katex expressions (inline and blocks)

    image

  • I got similar problems when solving a kata. I did a copy/paste from a description to the editor in a trainer: the description looks fine, but once the selected text has been pasted, I got triplets of it in the trainer in some situations. It looks like it happens only when copying inline katex expressions.
    Example here (warning: trainer link!) https://www.codewars.com/kata/56347fcfd086de8f11000014/train/typescript

    • select the whole inline expression A0​(x0​,y0​) (3rd §) and paste in the trainer => triplets: A0(x0,y0) A_0 (x_0, y_0) A0​(x0​,y0​)
    • select a whole inline expression with text surrounding it (before or after or both) + paste => triplets
    • select a part of it only + paste => ok
    • select a part of the katex block just above or a complete line of it or the whole block + paste => ok

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
Copy link
Member

kazk commented Jul 25, 2022

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
Copy link
Author

Blind4Basics commented Jul 25, 2022

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 A0and then the tangent line at A0 A_0 A0.

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

−2x.

For each xk x_k xkwe are able to calculate the yk y_k ykas well as the values zk z_k zkof the exact solution.

Our task

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

@kazk
Copy link
Member

kazk commented Jul 25, 2022

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
Copy link
Member

kazk commented Jul 25, 2022

Probably KaTeX/KaTeX#645

@kazk
Copy link
Member

kazk commented Jul 25, 2022

The first one should be fixed.

@kazk
Copy link
Member

kazk commented Jul 25, 2022

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 (cure53/DOMPurify#673).

Not sure what can be done.

@Blind4Basics
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants