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 bold, code, link input rules #2

Merged
merged 22 commits into from
Jul 7, 2021
Merged

Add bold, code, link input rules #2

merged 22 commits into from
Jul 7, 2021

Conversation

hamvocke
Copy link
Contributor

@hamvocke hamvocke commented Dec 9, 2020

This PR introduces input rules for common mark types. It allows you to type commonmark notation in rich-text mode and trigger automated conversion to bold and emphasized text, links and inline code.

This PR supports:

  • **bold** and __bold__
  • *em* and _em
  • [link](https://stackoverflow.com) (including link validation to avoid entering URLs you wouldn't be able to enter via our link tooltip)
  • `code`

The fundamental implementation is inspired by this discussion. It's relying on regular expressions and a bunch of conventions surrounding them: the regex needs to match a capture group, the first group is the text to be kept for the marked text. I tried to make the conventions and regexes a little easier to work with by providing documentation and a good bunch of unit tests. I've also added e2e tests.

Demo
Kapture 2021-06-17 at 11 11 18

@hamvocke hamvocke added the enhancement New feature or request label Dec 9, 2020
@aalear
Copy link
Member

aalear commented Jun 16, 2021

@hamvocke Any plans to do more work here in the near term? I'm dying without the inline code input rule in RT mode. 😅

Happy to help with this PR or extract the code rule parts into a new one.

@hamvocke
Copy link
Contributor Author

I feel you! This is my most anticipated feature, personally. Let me try to get those e2e tests in today. With that, the only remaining thing is link validation. I'll try to come up with a suggestion for that but that. I'll keep you posted!

@hamvocke hamvocke requested review from b-kelly and aalear June 17, 2021 08:54
@hamvocke hamvocke marked this pull request as ready for review June 17, 2021 09:12
Copy link
Collaborator

@b-kelly b-kelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I did a little playing around with this locally and you covered what looks like 90% of the functionality. I did correct a small bug where it would attempt to insert marks in places that they weren't allowed.

Additionally, I came up with a new approach for unit testing these rules. The method is not terribly straightforward (and a bit hacky), but it works pretty well.

lgtm!

@b-kelly b-kelly merged commit 4814922 into main Jul 7, 2021
@b-kelly b-kelly deleted the mark-input-rules branch July 7, 2021 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants