CodeEditApp / CodeEdit

CodeEdit App for macOS – Elevate your code editing experience. Open source, free forever.
https://codeedit.app
MIT License
20.98k stars 1.01k forks source link

✨ Markdown Preview #567

Open jenslys opened 2 years ago

jenslys commented 2 years ago

Describe the solution you'd like

Would be nice to have a feature where you can preview your markdown(.md) files within CodeEdit. Preferably matching GitHub's styling. Where you also could switch between dark and light mode.

Example preview from VS CODE:

https://cln.sh/MzuGHDycazmyxGssnWqp

Resources

ghost commented 2 years ago

@jenslys So you mean raw and formatted text? Supporting HTML and Markdown? I can work on something like that. Unfortunately, there are only messy, complicated ways to do this using the SwiftUI WebView, so we might have to add a bit of JavaScript rooted into SwiftUI.

leon-wolf commented 1 year ago

I you like you can assign me to this issue and i would take a look :)

austincondiff commented 1 year ago

@leon-wolf, I've assigned it to you, but we may consider the following before starting this task:

  1. Should this be an extension (it would still ship with CodeEdit)
    • If yes: can we work on it now in the core and move it into an extension later or should we wait until we have a more solidified Extensions API?
  2. Should the preview be in the same tab or a separate tab?
    • If same tab: should it split the layout within the tab aside from planned editor split layouts?
    • If separate: should we open a split editor if one does not yet exist with the tab open?

Note: Xcode has the concept of the preview canvas within the same tab, so for whatever thats worth.

image

  1. Should the preview be open by default?

  2. For .md files only, .mdx?

  3. Command, menu item, keyboard shortcut to show/hide preview?

  4. Because markdown outputs html, would it be appropriate to render the preview in a webview or do we want to try to parse it as a native view?

  5. Do we want to handle markdown flavors?

CC: @CodeEditApp/maintainers

austincondiff commented 1 year ago

Here is a potential resource mentioned in Discord

StefKors commented 1 year ago

btw Swift UI supports markdown natively like so:

struct Markdown: View {

  var body: some View {
    VStack {
      Text(.init("**Hello** *World*"))
    }
  }

}

For finetuned control of rendering output you can read here how that works: https://developer.apple.com/documentation/swiftui/text/init(_:)-1a4oh

An alternative library can be found here: https://github.com/apple/swift-markdown

0xWDG commented 1 year ago

btw Swift UI supports markdown natively like so:

struct Markdown: View {

  var body: some View {
    VStack {
      Text(.init("**Hello** *World*"))
    }
  }

}

For finetuned control of rendering output you can read here how that works: developer.apple.com/documentation/swiftui/text/init(_:)-1a4oh

An alternative library can be found here: apple/swift-markdown

Yup, but it does not support images, so it is no direct replacement unfortunately.

jacob-carlborg commented 1 year ago
  1. Should this be an extension (it would still ship with CodeEdit)

Probably.

  1. Should the preview be in the same tab or a separate tab?

Ideally configurable.

  1. Should the preview be open by default?

Ideally configurable.

  1. For .md files only, .mdx?

Ideally configurable. In TextMate the user can freely map file extensions to languages. Then all commands are tied to languages and not file extensions. Languages are recognized based of file extensions. Bundles come with a set of preconfigured mappings.

  1. Command, menu item, keyboard shortcut to show/hide preview?

Yes.

  1. Because markdown outputs html, would it be appropriate to render the preview in a webview or do we want to try to parse it as a native view?

Probably a webview since it's usually possible to include a few selected raw HTML tags.

  1. Do we want to handle markdown flavors?

GitHub flavored Markdown would be nice.

I think many of these questions are related to the first question. The way this is done in TextMate is via a bundle (extension). TextMate has a generic output window. The bundle chooses the type of output, plain text or HTML. For HTML TextMate will open a output window with a webview. For plain text it will just render the text in the output window. Since the output window is not tied to the Markdown feature, but a generic feature of TextMate, it's possible to configure if it should open a new window or open a new pane within the existing window. It's also possible to configure the placement of the pane. The Markdown bundle that ships with TextMate is for regular Markdown. But, since it's just a bundle, there are other bundles available that support various Markdown flavors.

If the feature is not implemented as an extension and instead built-in, and the output pane/window/tab is specific for the Markdown feature, then it might not be worth support various settings on how/when/where the output should appear. But if it's a generic output view that can be reused for other things, then I definitely think the placement of the view should be configurable.

In TextMate the output window is used for other bundles as well, like the HTML bundle. It has a Preview command, just as the Markdown bundle. Same name of the command/menu item, same keyboard shortcut, they all follow the same convention. See my comment here https://github.com/CodeEditApp/CodeEdit/issues/262#issuecomment-1404211388 which is a bit related.

TheGlorySaint commented 1 month ago

I Love Codeedit, have you guys thought about when this enhancement will be added?

rcarmo commented 2 weeks ago

Curious to know if anything is happening regarding this since Markdown is a critical part of the documentation workflow for me.

thecoolwinter commented 2 weeks ago

Curious to know if anything is happening regarding this since Markdown is a critical part of the documentation workflow for me.

I don't think anyone is actively working on this right now, but it's 100% a planned feature. We're allocating more time towards things like LSP support and continued improvements to source control right now