Add initial markdown preview to Zed (#6958)

Adds a "markdown: open preview" action to open a markdown preview.

https://github.com/zed-industries/zed/assets/18583882/6fd7f009-53f7-4f98-84ea-7dd3f0dd11bf


This PR extends the work done in `crates/rich_text` to render markdown
to also support:

- Variable heading sizes
- Markdown tables
- Code blocks
- Block quotes

## Release Notes

- Added `Markdown: Open preview` action to partially close
([#6789](https://github.com/zed-industries/zed/issues/6789)).

## Known issues that will not be included in this PR

- Images.
- Nested block quotes.
- Footnote Reference.
- Headers highlighting.
- Inline code highlighting (this will need to be implemented in
`rich_text`)
- Checkboxes (`- [ ]` and `- [x]`)
- Syntax highlighting in code blocks.
- Markdown table text alignment.
- Inner markdown URL clicks
This commit is contained in:
Kieran Gill 2024-02-01 04:03:09 -05:00 committed by GitHub
parent 3b882918f7
commit 8bafc61ef5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 547 additions and 8 deletions

View file

@ -22,7 +22,7 @@ futures.workspace = true
gpui = { path = "../gpui" }
language = { path = "../language" }
lazy_static.workspace = true
pulldown-cmark = { version = "0.9.2", default-features = false }
pulldown-cmark.workspace = true
smallvec.workspace = true
smol.workspace = true
sum_tree = { path = "../sum_tree" }

View file

@ -47,7 +47,7 @@ pub struct Mention {
}
impl RichText {
pub fn element(&self, id: ElementId, cx: &mut WindowContext) -> AnyElement {
pub fn element(&self, id: ElementId, cx: &WindowContext) -> AnyElement {
let theme = cx.theme();
let code_background = theme.colors().surface_background;
@ -83,7 +83,12 @@ impl RichText {
)
.on_click(self.link_ranges.clone(), {
let link_urls = self.link_urls.clone();
move |ix, cx| cx.open_url(&link_urls[ix])
move |ix, cx| {
let url = &link_urls[ix];
if url.starts_with("http") {
cx.open_url(url);
}
}
})
.tooltip({
let link_ranges = self.link_ranges.clone();
@ -256,7 +261,7 @@ pub fn render_markdown_mut(
}
}
pub fn render_markdown(
pub fn render_rich_text(
block: String,
mentions: &[Mention],
language_registry: &Arc<LanguageRegistry>,