-
Notifications
You must be signed in to change notification settings - Fork 41
Add pasting URLs on selected text as Markdown links #23
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
Conversation
koddsson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Can we add tests for some of this functionality? Also adding an example on the demo page.
Co-authored-by: Kristján Oddsson <[email protected]>
Co-authored-by: Kristján Oddsson <[email protected]>
|
@koddsson Thank you for your quick and great suggestions! 🙇♂️ I think I've resolved all your inline suggestions as well as the following:
Do you think this test is sufficient? d4c60b1
I've added an example on the demo page here: 460e1b6 I'm happy and open for any other suggestions. Thank you! |
koddsson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks generally good to me. I had a couple of questions and suggestions.
This is changing the API so this will be a breaking change.
| function subscribe(el: HTMLElement): Subscription { | ||
| installTable(el) | ||
| installLink(el) | ||
| installImageLink(el) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about having all the install* functions in here so that consumers that use subscribe will get all the features, but then if they want to conditionally apply features they can import only the installers they plan on using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koddsson I've thought about that as well. Do you know if this line is the only place where we consume the library at GitHub?
Since subscribe is now a named export, users of the library have to adjust the usage of the library either way, so yeah, I agree with adding the new feature to subscribe right away. We then only need to adjust this line as well to use the add and remove hooks as I do in the lines below so that the new Link feature is not loaded by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koddsson I just saw your proposal on using the add and remove hooks for all functions. I missed that earlier. I'll go with that approach. 👍 Thank you! 🙇♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| if (selectionStart > 1) { | ||
| const previousChars = textarea.value.substring(selectionStart - 2, selectionStart) | ||
| return previousChars === '](' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about checking for HTML links as well? Since markdown generally supports HTML as well, should we check if we're in a <a> tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought about some other edge cases as well, for example let's say you have this issue template:
Repository: [URL of repository]
If you select [URL of repository] and paste an URL on top of it, with the new feature it would now convert it to [[URL of repository]](url).
Though, I'm not sure we should account for all edge cases or if users will learn quickly that they need to delete the selected text first and then paste the URL in order to have the URL as is.
Regarding detecting if the selected text is within an <a> tag:
Do you think of the use case where a user would have an -link in their Markdown, such as <a href="https://some-url">Docs</a>, and where they would want to change the href by selecting the https://some-url part and replace it with another URL?
@koddsson I agree. I've raised the breaking of the API here. @koddsson Do you think including a breaking change for 0.4.x is reasonable? Not sure what version schema paste-markdown follows, for semver the major version would need to be bumped, e.g. 0.3.x -> 1.0.0. |
|
Friendly bump on this PR @github/ui-frameworks-reviewers as I will be off on Friday and I would love to release and deploy these changes this week. Thank you! 🙇♂️ |
|
👋 I love making it easier to write markdown! Could you share some more of the motivation here? Users can currently highlight text, click cmd-k and get an empty markdown link that they can then fill in with cmd-v. I personally would find it surprising that cmd-v would not overwrite the text I've selected (and IMO be annoying). I also wonder about making cmd-v be the default (I think it's not configurable?) for the library as a whole as opposed to a configuration option. WDYT? edit - I've since been educated that most of the internet already does this ;). Carry on! |
@srt32 😂 Fair points! I will definitely detail my motivation behind this in our internal staff-shipping post. In short, I believe once you see selected text automagically converted to a link for the first time, you don't want to go back anymore. 😄 Also, I made the functionality feature-flaggable so that we can first enable it for individuals only and then staff-ship it and gather feedback. Thank you for looking into this PR! 🙇♂️❤️ |
|
👋 What is remaining to get this PR merged? 🙇♂️ |
srt32
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm cool to merge this. Do we have a plan for the change in versions?
🙇♂️
@srt32 I think that would be best. Not sure what version scheme is followed, but this change is a breaking change as it changes the API. So it's now: import {subscribe} from '@github/paste-markdown'instead of import subscribe from '@github/paste-markdown'This reminds me that we need to update the README as well, which I will do in a moment. (Done: 6c4781f) @Bestra had the idea to use a default export and a named export. Though, |
Woohoo, thank you @srt32! 🎉 🙇♂️ |
This pull request adds pasting URLs on selected text as Markdown links.
In order to test this new functionality:
https://docs.github.comor any other URLYou can find the docs here.hereResult: You should now see a Markdown link:
[here](https://docs.github.com)