Skip to content

Commit c3b150d

Browse files
RemcoSmitsDevtidely
authored andcommitted
markdown: Add support for inline HTML img tags inside text (zed-industries#37264)
Follow-up: zed-industries#36700 This PR adds basic support for showing images inline inside a text. As you can see inside the before screenshot, the image was displayed right below the `Some inline text` text. This was because we didn't consider the image to be inline with the text (paragraph). Now we do :) All the test changes are making sure it is not more than 1 element parsed, instead of only checking for the first parsed element. This could work out bad when we return more than 1 result. **Before** <img width="1717" height="1344" alt="Screenshot 2025-08-31 at 13 49 45" src="https://github.com/user-attachments/assets/13c5f9dd-0e0a-4e08-b2a6-28e9a4e0cab8" /> **After** <img width="1719" height="1343" alt="Screenshot 2025-08-31 at 13 42 14" src="https://github.com/user-attachments/assets/bf7aa82f-3743-4fb3-87aa-4a97a550c4d1" /> **Code example**: ```markdown <p>some inline text <img src="https://picsum.photos/200/300" alt="Description of image" style="height: 100px" /> asdjkflsadjfl</p> # Html Tag <img src="https://picsum.photos/200/300" alt="Description of image" /> # Html Tag with width and height <img src="https://picsum.photos/200/300" alt="Description of image" width="100" height="200" /> # Html Tag with style attribute with width and height <img src="https://picsum.photos/200/300" alt="Description of image" style="width: 100px; height: 200px" /> # Normal Tag ![alt text](https://picsum.photos/200/300) ``` Release Notes: - Markdown: Added support for inline HTML `img` tags inside paragraphs
1 parent 1cef737 commit c3b150d

File tree

3 files changed

+172
-86
lines changed

3 files changed

+172
-86
lines changed

crates/markdown_preview/src/markdown_elements.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct ParsedMarkdownText {
155155
/// Where the text is located in the source Markdown document.
156156
pub source_range: Range<usize>,
157157
/// The text content stripped of any formatting symbols.
158-
pub contents: String,
158+
pub contents: SharedString,
159159
/// The list of highlights contained in the Markdown document.
160160
pub highlights: Vec<(Range<usize>, MarkdownHighlight)>,
161161
/// The regions of the various ranges in the Markdown document.

0 commit comments

Comments
 (0)