zed icon indicating copy to clipboard operation
zed copied to clipboard

markdown_preview: Improved markdown rendering support

Open kierangilliam opened this issue 1 year ago • 2 comments

This PR improves support for rendering markdown documents.

After the updates

https://github.com/zed-industries/zed/assets/18583882/48315901-563d-44c6-8265-8390e8eed942

Before the updates

https://github.com/zed-industries/zed/assets/18583882/6d7ddb55-41f7-492e-af12-6ab54559f612

New features

  • @SomeoneToIgnore's scrolling feature request.
  • Checkboxes (- [ ] and - [x])
  • Inline code blocks.
  • Ordered and unordered lists at an arbitrary depth.
  • Block quotes that render nested content, like code blocks.
  • Lists that render nested content, like code blocks.
  • Block quotes that support variable heading sizes and the other markdown features added here.
  • Users can see and click internal links ([See the docs](./docs.md)).

Notable changes

  • Removed dependency on rich_text.
  • Added a new method for parsing markdown into renderable structs. This method uses recursive descent so it can easily support more complex markdown documents.
  • Parsing does not happen for every call to MarkdownPreviewView::render anymore.

TODO

  • [ ] Typing should move the markdown preview cursor.

Future work under consideration

  • If a title exists for a link, show it on hover.
  • Images.
  • Since this PR brings the most support for markdown, we can consolidate languages/markdown and rich_text to use this new renderer. Note that the updated inline text rendering method in this PR originated from langauges/markdown.
  • Syntax highlighting in code blocks.
  • Footnote references.

Release Notes

  • Improved support for markdown rendering.

kierangilliam avatar Feb 03 '24 22:02 kierangilliam

Hey @kierangilliam, thank you for your killer work here. We've been wanting this markdown preview for a long time and to see it appear and improve incrementally is awesome! I didn't check any code, but I did do some testing, and one thing I noticed: the text on tasks is gone now.

Main:

SCR-20240205-dpme

This branch:

SCR-20240205-dpcm

I realize tasks weren't implemented before, but the text being gone now is a regression from its previous state.

JosephTLyons avatar Feb 05 '24 08:02 JosephTLyons

I did do some testing, and one thing I noticed: the text on tasks is gone now.

...

I realize tasks weren't implemented before, but the text being gone now is a regression from its previous state.

@JosephTLyons

For whatever reason, I forgot to include tasks in my playground markdown file. Thanks for the callout. This was an easy add. They are now implemented in this PR:

image

How I render checked / unchecked is not ideal. I can revisit that when I get more free time.

kierangilliam avatar Feb 05 '24 12:02 kierangilliam

@SomeoneToIgnore As always — thanks for the thorough feedback. I’ll look at the list rendering issue when I get a chance.

I agree that the scrolling UX isn’t the best. I’m not sure why the list state doesn’t persist as expected. @mikayla-maki and I had chatted about this previously. Mikayla, do you have any idea how I could work around this?

Would you all prefer deferring scrolling until I can more holistically address your comments?

I agree with the rest of your list. These sound like good follow-up issues.

kierangilliam avatar Feb 06 '24 23:02 kierangilliam

I would rather prefer to have Zed's syntax tree behavior: there's always a single panel that renders things for whatever tab is active now. At least we should not split if there's already a split, rather adding the new rendered tab there.

Yes! This sounds like a very sane behavior.

berkus avatar Feb 07 '24 08:02 berkus

❤️

(I'm slowly going through my list of things that are needed to make Zed my default editor instead of VSCode, one more checkmark!)

berkus avatar Feb 08 '24 10:02 berkus