Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "emphasis" markdown shortcuts #62243

Open
bacoords opened this issue Jun 3, 2024 · 4 comments · May be fixed by #62289
Open

Add support for "emphasis" markdown shortcuts #62243

bacoords opened this issue Jun 3, 2024 · 4 comments · May be fixed by #62289
Assignees
Labels
[Package] Format library /packages/format-library [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@bacoords
Copy link
Contributor

bacoords commented Jun 3, 2024

What problem does this address?

Right now Gutenberg has mixed support for markdown-style text shortcuts. You can use shortcuts to generate heading blocks (#), lists (-), and the horizontal rule (---). Using the ` (backtick) character will create an inline code tag for you. But there are a few others that could be helpful while writing.

What is your proposed solution?

Similar to the way Gutenberg recognizes the backtick character and converts it to code, I would like to work on extending that support to emphasis as the scope of this issue.

The ideal result here would be that users could type a single or double asterisk * or underscore _ to get <em> or <strong> tags inline.

https://daringfireball.net/projects/markdown/syntax#em

@bacoords bacoords added the [Type] Enhancement A suggestion for improvement. label Jun 3, 2024
@Mamaduka Mamaduka added the [Package] Format library /packages/format-library label Jun 3, 2024
@Mamaduka
Copy link
Member

Mamaduka commented Jun 4, 2024

If you want to give it a try, check out the __unstableInputRule property for Code format.

Swapping the const BACKTICK = '`'; with const ASTERISK = '*'; should probably be enough for essential support.

@bacoords
Copy link
Contributor Author

bacoords commented Jun 4, 2024

Thanks for the pointer @Mamaduka ! - You're right that emphasis was easy enough. I am seeing that the harder part is that in markdown, a *single asterisk* translates to <em> but a **double asterisk** translates to <strong> so I think I need to put a little more logic for that.

@Mamaduka
Copy link
Member

Mamaduka commented Jun 4, 2024

IIRC formats can only support a single tagName; based on that "limitation", your PR shouldn't be enough for the core.

A plugin can register a custom format that handles "strong importance" for a text.

@bacoords bacoords linked a pull request Jun 4, 2024 that will close this issue
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jun 4, 2024
@bacoords
Copy link
Contributor Author

bacoords commented Jun 4, 2024

I've updated the PR. There should only be a single tagName added- <em> or <strong>. There needed to be some additional logic in italic/index.js to make sure that it worked correctly and I'll admit that I left the logic a bit more verbose so it could be more clear what was happening. Open to any suggestions on tightening it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Format library /packages/format-library [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
2 participants