diff --git a/README.md b/README.md index a6c7273..da87c50 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,12 @@ $ npm install @github/quote-selection ```js import {install} from '@github/quote-selection' -install(document.querySelector('.my-quote-region')) +const controller = new AbortController() + +install(document.querySelector('.my-quote-region'), { signal: controller.signal }) + +// For when you want to uninstall later: +const uninstall = () => controller.abort() ``` This sets up a keyboard event handler so that selecting any text within `.my-quote-region` and pressing r appends the quoted representation of the selected text into the first applicable ` ` - install(document.querySelector('[data-quote]')) - subscription = subscribe(document.querySelector('[data-nested-quote]')) + controller = new AbortController() + + install(document.querySelector('[data-quote]'), {signal: controller.signal}) + install(document.querySelector('[data-nested-quote]'), {signal: controller.signal}) }) afterEach(function () { - uninstall(document.querySelector('[data-quote]')) - subscription.unsubscribe() + controller.abort() document.body.innerHTML = '' }) @@ -94,7 +96,7 @@ describe('quote-selection', function () { }) describe('with markdown enabled', function () { - let subscription + let controller beforeEach(function () { document.body.innerHTML = `
@@ -112,21 +114,28 @@ describe('quote-selection', function () {
` - subscription = subscribe(document.querySelector('[data-quote]'), { + controller = new AbortController() + install(document.querySelector('[data-quote]'), { quoteMarkdown: true, - scopeSelector: '.comment-body' + scopeSelector: '.comment-body', + signal: controller.signal }) }) afterEach(function () { - subscription.unsubscribe() + controller.abort() document.body.innerHTML = '' }) it('preserves formatting', function () { const range = document.createRange() range.selectNodeContents(document.querySelector('.comment-body').parentNode) - assert.ok(quote('whatever', range)) + assert.ok( + quote('whatever', range, { + quoteMarkdown: true, + scopeSelector: '.comment-body' + }) + ) const textarea = document.querySelector('textarea') assert.equal( @@ -158,7 +167,12 @@ describe('quote-selection', function () { const range = document.createRange() range.selectNodeContents(document.querySelector('.comment-body').parentNode) - assert.ok(quote('whatever', range)) + assert.ok( + quote('whatever', range, { + quoteMarkdown: true, + scopeSelector: '.comment-body' + }) + ) const textarea = document.querySelector('textarea') assert.match(textarea.value, /^> @links and :emoji: are preserved\./m)