Skip to content

Support inline code blocks in commit messages, like github #18104

Open

Description

@moritztim

The feature request

Unlike on github, github desktop does not support markdown inline code blocks in commit messages
Github Desktop

Here's what this looks like on the website:
Github web repo overview
Github web commit view

Proposed solution

I suggest that within the commit message input field, anything surrounded with ` is rendered in a monospace font and elsewhere it's rendered as a code block like this.

Additional context

No response

Added as also in scope: #18291

The feature request
I often enclose code parts in backticks when writing commit messages. For example, this is a commit message I just made:

Rename addChildren method to addItems
Writing backticks takes time, so it would be great if Desktop could support the same CMD/CTRL+E shortcut as GitHub uses.

Proposed solution
Pressing CMD/CTRL+E adds backticks around the selected text

Additional context
No response

Activity

  1. changed the title [-]Support inline `code block` in commit messages, like github[/-] [+]Support inline `code block`s in commit messages, like github[/+] on Jan 30, 2024
  2. DylanDevelops commented on Feb 2, 2024

    @DylanDevelops
    Contributor

    I'm down to take on this issue. Can someone point me in the right direction on how a feature like this would be implemented?

  3. tidy-dev commented on Feb 12, 2024

    @tidy-dev
    Contributor

    @DylanDevelops Thanks for wanting to take this on!

    Some context as there are a couple way to go about this. For our current commit summaries and descriptions we use our RichText component and it in turn uses a custom Tokenizer to search for patterns and replace them with generated html. These patterns currently include emoji's, issue references, username references, and hyperlinks. Theoretically, we could simply add another token search to it for the backticks. Unfortunately, that would look something like "grab random input from user between backticks" and inject into html. Opening up possibilities for script injection.. so a no go.

    We do have somewhere in the app that we do parse markdown such as the code blocks. It is our SandboxedMarkdown component. We currently use this for showing PR comments in conjunction with our notifications about PRs. How it works is that it takes markdown and runs it through a sanitizer and then through a markdown parser and then renders the produced html in a sandboxed iframe. Thus, it even if a script injection makes it past the sanitizer and markdown parser, it would be isolated to the iframe.

    Tho, SandboxedMarkdown I believe (needs verified) does parse the same things as the Tokenizer used by the RichText component, simply substituting the RichText for the SandboxedMarkdown should be done with caution and investigation. Some drawbacks off the top of my head:

    • This would necessarily mean that we would parse any markdown tokens which may mean a different experience than dotcom and not necessarily expected behavior. One line summaries maybe alright tho since that should exclude things like headings and quotation blocks... but should be checked for other differences with dotcom. Maybe we would need to make the SandboxedMarkdown smarter and have the ability to turn off unwanted filters.
    • The SandboxedMarkdown Parser maybe slower than the Tokenizer since it is parsing for multiple things. (Back to turning off unwanted filters..might be more efficient)
    • The SandboxedMarkdown parser is an iframe and will take some more css effort to make it look seemless. Need to make sure it plays nicely with the expandable commit summary. Also, that it reads and links are navigable as expected by screen readers for accessibility.

    Another potential more targeted solution would be to use the tokenizer in combination with the SandboxedMarkdown parser, that is, search for backticks and if found dump the backticks and anything inside them into the SandboxedMarkdown parser. I know a lot of the filters in the markdown parser are setup to basically skip if the backticks are present so this may lend for an efficient solution. The drawbacks are still similar to above tho and should be considered.

  4. DylanDevelops commented on Mar 29, 2024

    @DylanDevelops
    Contributor

    So sorry, I've been really busy. I may be able to get to this, this weekend.

  5. DylanDevelops commented on Apr 24, 2024

    @DylanDevelops
    Contributor

    I am having trouble figuring out how to implement this feature. If this is still something that we would like to implement, would someone be willing to help me out a little bit?

    Mostly I just need to understand exactly how I should apply the new rendering code into the current codebase. Which files should I look at specifically?

  6. added
    not-planned
    on Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnot-planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions