-
Notifications
You must be signed in to change notification settings - Fork 6k
markdown: Add support for HTML styling elements
#37765
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
markdown: Add support for HTML styling elements
#37765
Conversation
This reverts commit c3860f3.
We will later fix the wrapping issues
Reverting this because see: zed-industries@8b8186a#r2322518759 This reverts commit 8b8186a.
HTML styling elementsHTML styling elements
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'm quite out of the context here, and decided to check on how images are rendered.
It also fixes an issue where we would insert an extra paragraph for new line text that resulted in adding a new line inside the markdown.
- Here, it seems that all the padding (?) around the images and items is gone.
https://github.com/rust-lang/rust-analyzer/blob/master/docs/book/src/contributing/debugging.md
Current Zed shows it a bit better?
- Here, there's a large spacing between images compared to what GH renders:
https://github.com/rust-lang/rust-analyzer/blob/master/docs/book/src/contributing/guide.md
Current Zed seems to do the same.
- As very well noted in #37264 (comment) seems like there's a regression:
Should we, instead of piling more changes, fix this trash first?
This got reverted in #37893, but overall was right, it seems, so if we get this back, let's ensure Zed's markdowns are rendered normally.
- and 2. would be nice to improve too, but this
iswas a straight regression.
|
@Angelk90 i think that is more a ui/ux issue. This pr just adds basic support for styling attributes. We can extend this in the future with more css properties. So its a bit out of scope for what i wanted to add/fix |
|
@RemcoSmitsDev : I understand, you might consider fixing it in the future. |
|
Yeah for sure! |
|
This PR is depending/waiting on inline elements support, to correctly show all the cases you could use style tags. See screenshot impl without showing the style tags inline with the flex & flex-wrap @SomeoneToIgnore Do you have time to brainstorm about how we could support inline elements. I already did some digging in how we could support this, and I tried to implement this inside taffy, but it seems there is a limitation because you can't wrap a part of the text to parent block start position if it's inline displayed. See current impl for inline support with taffy Screen.Recording.2025-09-20.at.17.09.07.mov |
|
Sorry, I have no good clues on this and improving markdown rendering is not in any of the company's intermediate plans: from my side, I'm mainly concentrating on rainbow brackets, LSP features like inlays/semantic highlights and community work (PR reviews alone is huge). I'm happy to help to do a basic review and testing, but not sure can handle anything more intelligent on top. |
|
I've actually agreed with @bennetbo to get the related PRs over to him, as he has definitely more context than me on what's going on and could suggest something (❤️ ) |
|
Sorry for taking so long to review. I'll close this for now as there are conflicts. If you'd like to fix the conflicts & re-open I'm happy to review (Feel free to ping me, and I'll make sure to review it quickly) |
|
Happy to fix the conflicts but don't think the PR good enough to merge as it does not support showing the text inline for these HTML elements. I have an idea how we could get around it, will try that out soon, but need's some refactoring I think. |
Second take on #37765. This PR adds support for styling elements (**b**, **strong**, **em**, **i**, **ins**, **del**), but also allow you to show the styling text inline with the current text. This is done by appending all the up-following text into one text chunk and merge the highlights from both of them into the already existing chunk. If there does not exist a text chunk, we will create one and the next iteration we will use that one to store all the information on. **Before** <img width="483" height="692" alt="Screenshot 2025-11-06 at 22 08 09" src="https://github.com/user-attachments/assets/6158fd3b-066c-4abe-9f8e-bcafae85392e" /> **After** <img width="868" height="300" alt="Screenshot 2025-11-06 at 22 08 21" src="https://github.com/user-attachments/assets/4d5a7a33-d31c-4514-91c8-2b2a2ff43e0e" /> **Code example** ```html <p>some text <b>bold text</b></p> <p>some text <strong>strong text</strong></p> <p>some text <i>italic text</i></p> <p>some text <em>emphasized text</em></p> <p>some text <del>delete text</del></p> <p>some text <ins>insert text</ins></p> <p>Some text <strong>strong text</strong> more text <b>bold text</b> more text <i>italic text</i> more text <em>emphasized text</em> more text <del>deleted text</del> more text <ins>inserted text</ins></p> <p><a href="https://example.com">Link Text</a></p> <p style="text-decoration: underline;">text styled from style attribute</p> ``` cc @bennetbo **TODO** - [x] add tests for styling nested text that should result in one merge Release Notes: - Markdown Preview: Added support for `HTML` styling elements --------- Co-authored-by: Bennet Bo Fenner <[email protected]>
…2143) Second take on zed-industries#37765. This PR adds support for styling elements (**b**, **strong**, **em**, **i**, **ins**, **del**), but also allow you to show the styling text inline with the current text. This is done by appending all the up-following text into one text chunk and merge the highlights from both of them into the already existing chunk. If there does not exist a text chunk, we will create one and the next iteration we will use that one to store all the information on. **Before** <img width="483" height="692" alt="Screenshot 2025-11-06 at 22 08 09" src="https://github.com/user-attachments/assets/6158fd3b-066c-4abe-9f8e-bcafae85392e" /> **After** <img width="868" height="300" alt="Screenshot 2025-11-06 at 22 08 21" src="https://github.com/user-attachments/assets/4d5a7a33-d31c-4514-91c8-2b2a2ff43e0e" /> **Code example** ```html <p>some text <b>bold text</b></p> <p>some text <strong>strong text</strong></p> <p>some text <i>italic text</i></p> <p>some text <em>emphasized text</em></p> <p>some text <del>delete text</del></p> <p>some text <ins>insert text</ins></p> <p>Some text <strong>strong text</strong> more text <b>bold text</b> more text <i>italic text</i> more text <em>emphasized text</em> more text <del>deleted text</del> more text <ins>inserted text</ins></p> <p><a href="https://example.com">Link Text</a></p> <p style="text-decoration: underline;">text styled from style attribute</p> ``` cc @bennetbo **TODO** - [x] add tests for styling nested text that should result in one merge Release Notes: - Markdown Preview: Added support for `HTML` styling elements --------- Co-authored-by: Bennet Bo Fenner <[email protected]>

Follow-up: #37264
This PR adds support for all the common HTML styling elements (
b,strong,em,i,ins,del).It also fixes an issue where we would insert an extra paragraph for new line text that resulted in adding a new line inside the markdown.
Before
After
Code example:
cc @SomeoneToIgnore
Release Notes: