You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
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.
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.