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

Code blocks inside spoiler tags are displayed incorrectly #28685

Open
UnlimitedCookies opened this issue Dec 8, 2024 · 3 comments
Open

Code blocks inside spoiler tags are displayed incorrectly #28685

UnlimitedCookies opened this issue Dec 8, 2024 · 3 comments
Labels
A-Markdown O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect

Comments

@UnlimitedCookies
Copy link

UnlimitedCookies commented Dec 8, 2024

Steps to reproduce

Writing /spoiler and then inserting ``` right after, then the code in multiple lines and then ``` again in its own line yields some weird reformatting, that definitely does not what we are looking for.

Also the following command does not yield a proper code block:

/html <span data-mx-spoiler><pre><code class="language-rs">fn main() {
    println!("Hallo Alex!");
}</code></pre></span>

Outcome

I expect code blocks inside spoiler tags to correctly highlight and display the line numbers inside the code block.
There should also be a way to nest a code block inside a spoiler tag without needing to type the HTML manually.

Operating system

Arch Linux

Browser information

Firefox 132.0.2

URL for webapp

No response

Application version

No response

Homeserver

matrix.org

Will you send logs?

No

@dosubot dosubot bot added A-Markdown O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist labels Dec 8, 2024
@alexanderthiem
Copy link

Same issue for
Windows
Edge: Version 131.0.2903.86 (Offizielles Build) (64-Bit)
Server tchncs

@alexanderthiem
Copy link

alexanderthiem commented Dec 8, 2024

What about instead of having the runfn in "element-web/src/SlashCommands.tsx" using the ContentHelpers.makeHtmlMessage()
which is imported from the as far as I know read only repo "matrix-js-sdk/src/matrix" simply create the html just as for normal messages:
call either
element-web/src/components/views/rooms/SendMessageComposer.ts#createMessageContent
or the function
element-web/src/editor/serialize.ts#htmlSerializeIfNeeded
with the reduced input string (aka remove the /spoiler) then afterwards wrap the formatted_body into the <span spoiler>.
(or even check isshlashcommand->getShlashcommand -> RunSlashcommand to allow for nested commands)

I think this also could solve some of the related problems as well:

  • spoiler reduces the whole text to one line,

  • avoid exploding escape characters from editing:
    currently, /html simply takes the html without unescaping anything, shows the html, when the message is edited, all html are removed and the most inner html is shown, correctly escaping special characters
    /spoil also takes the rest of the string as html, without unescaping anything, when the message is edited though, the deserialiser (element-web/src/editor/deserialize.ts) deserialised the /spoil command as well as escaping special characters.
    If the edited message is sent again though, there will be no unescaping, even though the deserialiser escaped this.

/tableflip and similar treat the rest of the line just as /plain does, so here every markdown or html is ignored too. why not allow nested commands here as well?

So all I could think of the following changes to allow for a cleaner and intuitive command and editing experience:

  • allow markddown/nesting after speicific commands (spoiler, tableflip etc) by formatting the args or checking for recursive commands
  • dont escape children of spoiler tag in deserialize
  • add a html span to deserialize html as well (and maybe spezialcase deserialisation of children to show the inner html too-afterall it was typed by the user)

@t3chguy
Copy link
Member

t3chguy commented Dec 9, 2024

which is imported from the as far as I know read only repo

Sorry how is it read-only

image

why not allow nested commands here as well?

Contributions welcome, keep in mind the autocomplete would have to work still, and you'd somehow have to be able to mark the end of a sub-command, so I don't forsee this being easy to implement nor grok as a user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Markdown O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect
Projects
None yet
Development

No branches or pull requests

3 participants