godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 93 forks source link

Add full Markdown support for use in browsing, creating, and editing projects and addons #139

Open willnationsdev opened 4 years ago

willnationsdev commented 4 years ago

Describe the project you are working on:

Designing solutions (either for editor changes or an addon) that involve browsing and displaying data regarding third-party addons.

Describe the problem or limitation you are having in your project:

Markdown README files are an industry-standard resource for sharing project information. Creators need to be able to edit and preview (render) them, and users need to be able to view (render) them. The Asset Library could then be refactored to render Markdown files (related to #12).

Describe how this feature / enhancement will help you overcome this problem or limitation:

  1. Allows users to employ more familiar and featureful technology than what Godot currently offers.
  2. Allows Godot to take advantage of a wealth of information already accessible on the Internet.
  3. Prevents users from needing to duplicate and maintain information between the Asset Library asset information (description) and the project's own README (the standard).
  4. Allows users to create, edit, and preview their own project's README directly from Godot rather than having to use a separate tool.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

This would be similar to how VS Code's Extensions tab looks. Below is an example for #12 on how things could appear in the Asset Library if refactored to display Markdown files.

extensions-popular.

In fact, @fenix-hub's TextEditor plugin already has a dedicated viewport with an editor and previewer for Markdown files, so it would be an excellent starting place for creating an extension to the built-in ScriptEditor that does the same.

Raw .md file:

MD_FILE

WIP conversion to rendered content (will eventually have headers, online images, etc.):

MD2_FILE

Describe implementation detail for your proposal (in code), if possible:

  1. Add an /editor/markdown_editor.h class for editing Markdown files and integrate it into the ScriptEditor.
  2. Add an /editor/markdown_renderer.h class for rendering a Markdown file's contents.
  3. Update the ScriptEditor in these scenarios to have a Tab, CheckButton, or similar for editing versus previewing the currently opened .md file. (hide when not editing a .md file).
  4. Update the EditorFileSystem dock to display .md files and allow them to be selected/edited.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

Most of the community using any sort of addon (either creating OR using) would use this, so almost everyone.

Yes, this could be done as a plugin in script code. No, it would not be just a few lines. It would be a huge amount of work just to create a well-written editor and renderer pair.

Is there a reason why this should be core and not an add-on in the asset library?:

Yes. The ScriptEditor integration portion is something that can only properly be done with direct editor modifications in the source code.

Furthermore, we are talking about an industry-standard text format. It should be built into the editing experience for all users, without the need for a plugin.

fire commented 4 years ago

From the module side there's two c based libraries for commonmark:

Edited:

See https://github.com/commonmark/cmark/blob/master/src/main.c#L75 for an example program.

fire commented 3 years ago

I have written a cmark github module. It takes commonmark input and outputs html.

https://github.com/godot-extended-libraries/cmark_gfm

image

fire commented 3 years ago

To write a walker for markdown to bbcode, this is how you do it.

void
usage_example(cmark_node *root) {
    cmark_event_type ev_type;
    cmark_iter *iter = cmark_iter_new(root);

    while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
        cmark_node *cur = cmark_iter_get_node(iter);
        // Do something with `cur` and `ev_type`
    }

    cmark_iter_free(iter);
}

I would create a String convert_bbcode(const String p_string); inside of the CommonmarkData class.

Edited:

https://www.systutorials.com/docs/linux/man/3-cmark/

fire commented 3 years ago

@greenfox1505 is investigating markdown/commonmark to RichTextLabel via the module I posted.

fire commented 3 years ago

https://github.com/fire/godot/tree/cmark was able do a patch

  1. markdown/common to html
  2. markdown/commonmark to text in a richtextlabel textbox

Wasn't able to do markdown/commonmark to richtextlabel as rich text.

fire commented 2 years ago

My branch changed to https://github.com/v-sekai/godot/tree/cmark.

joao-pedro-braz commented 9 months ago

I really like how IntelliJ-based IDEs handle Markdown, in that you can edit it and/or view it:

If we were to add Markdown support to the Editor I think we should do something similar, maybe by (like in IDEA) having three buttons to toggle between modes at the top of the Script Editor, like in this mock-up: image

fire commented 9 months ago

I don't know what state this is in but https://github.com/V-Sekai/godot/tree/vsk-cmark-4.2 is my current work branch. I wasn't able to work on the rich text code but its salvageable