markdown: Add support for HTML styling attributes (#42143)
Second take on https://github.com/zed-industries/zed/pull/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 <bennetbo@gmx.de>
This commit is contained in:
co-authored by
Bennet Bo Fenner
parent
74bf1a170d
commit
9591790d8d
@@ -222,6 +222,10 @@ impl MarkdownHighlight {
|
||||
});
|
||||
}
|
||||
|
||||
if style.oblique {
|
||||
highlight.font_style = Some(FontStyle::Oblique)
|
||||
}
|
||||
|
||||
Some(highlight)
|
||||
}
|
||||
|
||||
@@ -243,6 +247,8 @@ pub struct MarkdownHighlightStyle {
|
||||
pub weight: FontWeight,
|
||||
/// Whether the text should be stylized as link.
|
||||
pub link: bool,
|
||||
// Whether the text should be obliqued.
|
||||
pub oblique: bool,
|
||||
}
|
||||
|
||||
/// A parsed region in a Markdown document.
|
||||
|
||||
Reference in New Issue
Block a user