Install a shortcut to append selected text to a as a Markdown quote.</body></html>
Перейти к файлу
dependabot[bot] 8c266e4615
Bump y18n from 4.0.0 to 4.0.3
Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.3.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/y18n-v4.0.3/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/compare/v4.0.0...y18n-v4.0.3)

---
updated-dependencies:
- dependency-name: y18n
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-31 20:15:20 +00:00
.github
examples
src
test
.gitignore
.travis.yml
CODEOWNERS
LICENSE
README.md
karma.config.js
package-lock.json Bump y18n from 4.0.0 to 4.0.3 2023-10-31 20:15:20 +00:00
package.json
rollup.config.js
tsconfig.json

README.md

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.