Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Install a shortcut to append selected text to a <textarea> as a Markdown quote.

License

NotificationsYou must be signed in to change notification settings

github/quote-selection

Install a keyboard shortcutr to append selected text to a<textarea> as a Markdown quote.

Installation

$ npm install @github/quote-selection

Usage

<divclass="my-quote-region"><p>Text to quote</p><textarea></textarea></div>
import{install}from'@github/quote-selection'install(document.querySelector('.my-quote-region'))

This sets up a keyboard event handler so that selecting any text within.my-quote-region and pressingr appends the quoted representation of the selected text into the first applicable<textarea> element.

Preserving Markdown syntax

install(element,{quoteMarkdown:true,copyMarkdown:false,scopeSelector:'.comment-body'})

The optionalscopeSelector parameter 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.

IncopyMarkdown: true mode, the browser clipboard copy action is intercepted for user selections withinelement and the Markdown representation of the content is placed on clipboard under thetext/x-gfm MIME-type.

Events

  • quote-selection-markdown (bubbles: true, cancelable: false) - fired on the quote region to optionally inject custom syntax into thefragment element inquoteMarkdown: true mode
  • quote-selection (bubbles: true, cancelable: true) - fired on the quote region before text is appended to a textarea

For example, reveal a textarea so it can be found:

region.addEventListener('quote-selection',function(event){const{selection, selectionText}=event.detailconsole.log('Quoted text',selection,selectionText)consttextarea=event.target.querySelector('textarea')textarea.hidden=false// Cancel the quote behavior.// event.preventDefault()})

Development

npm installnpm test

License

Distributed under the MIT license. See LICENSE for details.

About

Install a shortcut to append selected text to a <textarea> as a Markdown quote.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors16


[8]ページ先頭

©2009-2025 Movatter.jp