You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
parse("<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>").await;
1548
+
1549
+
assert_eq!(1, parsed.children.len());
1550
+
let chunks = ifletParsedMarkdownElement::Paragraph(chunks) = &parsed.children[0]{
1551
+
chunks
1552
+
}else{
1553
+
panic!("Expected a paragraph");
1554
+
};
1555
+
1556
+
assert_eq!(1, chunks.len());
1557
+
let text = ifletMarkdownParagraphChunk::Text(text) = &chunks[0]{
1558
+
text
1559
+
}else{
1560
+
panic!("Expected a paragraph");
1561
+
};
1562
+
1563
+
assert_eq!(0..205, text.source_range);
1564
+
assert_eq!(
1565
+
"Some text strong text more text bold text more text italic text more text emphasized text more text deleted text more text inserted text",
1566
+
text.contents.as_str(),
1567
+
);
1568
+
assert_eq!(
1569
+
vec![
1570
+
(
1571
+
10..21,
1572
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1573
+
weight:FontWeight(700.0),
1574
+
..Default::default()
1575
+
},),
1576
+
),
1577
+
(
1578
+
32..41,
1579
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1580
+
weight:FontWeight(700.0),
1581
+
..Default::default()
1582
+
},),
1583
+
),
1584
+
(
1585
+
52..63,
1586
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1587
+
italic:true,
1588
+
weight:FontWeight(400.0),
1589
+
..Default::default()
1590
+
},),
1591
+
),
1592
+
(
1593
+
74..89,
1594
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1595
+
weight:FontWeight(400.0),
1596
+
oblique:true,
1597
+
..Default::default()
1598
+
},),
1599
+
),
1600
+
(
1601
+
100..112,
1602
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1603
+
strikethrough:true,
1604
+
weight:FontWeight(400.0),
1605
+
..Default::default()
1606
+
},),
1607
+
),
1608
+
(
1609
+
123..136,
1610
+
MarkdownHighlight::Style(MarkdownHighlightStyle{
1611
+
underline:true,
1612
+
weight:FontWeight(400.0,),
1613
+
..Default::default()
1614
+
},),
1615
+
),
1616
+
],
1617
+
text.highlights
1618
+
);
1619
+
}
1620
+
1411
1621
#[gpui::test]
1412
1622
asyncfntest_text_with_inline_html(){
1413
1623
let parsed = parse("This is a paragraph with an inline HTML <sometag>tag</sometag>.").await;
0 commit comments