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

Helpers for quoting selected text, appending the text into 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{Quote}from'@github/quote-selection'document.addEventListener('keydown',event=>{if(event.key=='r'){constquote=newQuote()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

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

UsingMarkdownQuote instead ofQuote will ensure markdown syntax is preserved.

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