No description
  • TypeScript 52.4%
  • JavaScript 47.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dusty Greif 30cf48997c
Improve supply chain configuration (#71)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-03 13:37:58 -04:00
.github Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
examples Replace Babel + Flow with TypeScript 2020-04-10 11:50:58 -06:00
src Address prettier warning 2024-06-04 15:41:18 +01:00
test Convert testing framework from Karma/Chai/Mocha to Vitest with Playwright (#63) 2025-10-07 09:50:16 -04:00
.gitignore Vitest config updates (#65) 2025-10-07 15:58:05 -04:00
.npmrc Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
.travis.yml Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
CODEOWNERS Create CODEOWNERS 2020-04-14 13:29:49 +01:00
LICENSE Update development dependencies 2020-04-10 09:21:35 -06:00
package-lock.json Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
package.json Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
README.md Fix README.md code blocks 2021-11-08 12:41:30 +00:00
rollup.config.js Replace Babel + Flow with TypeScript 2020-04-10 11:50:58 -06:00
tsconfig.json Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00
vitest.config.js Improve supply chain configuration (#71) 2026-06-03 13:37:58 -04:00

Quote selection

Helpers for quoting selected text, appending the text into a <textarea> as a Markdown quote.

Installation

$ npm install @github/quote-selection

Usage

<div class="my-quote-region">
  <p>Text to quote</p>
  <textarea></textarea>
</div>
import {Quote} from '@github/quote-selection'

document.addEventListener('keydown', event => {
  if (event.key == 'r') {
    const quote = new Quote()
    if (quote.closest('.my-quote-region')) {
      quote.insert(document.querySelector('textarea'))
    }
  }
})

Quote will take the currently selected HTML from the specified quote region, convert it to markdown, and create a quoted representation of the selection.

insert will insert the string representation of a selected text into the specified text area field.

Preserving Markdown syntax

const quote = new MarkdownQuote('.comment-body')
quote.select(document.querySelector('.comment-body'))
if (quote.closest('.my-quote-region')) {
  quote.insert(quote, document.querySelector('textarea'))
}

Using MarkdownQuote instead of Quote will ensure markdown syntax is preserved.

The optional scopeSelector parameter of MarkdownQuote ensures that even if the user selection bleeds outside of the scoped element, the quoted portion will always be contained inside the scope. This is useful to avoid accidentally quoting parts of the UI that might be interspersed between quotable content.

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.