Paste spreadsheet cells as a Markdown table.
Перейти к файлу
dependabot[bot] 143dc83b0d
Bump the npm_and_yarn group with 2 updates (#101)
Bumps the npm_and_yarn group with 2 updates: [@75lb/deep-merge](https://github.com/75lb/deep-merge) and [rollup](https://github.com/rollup/rollup).


Updates `@75lb/deep-merge` from 1.1.1 to 1.1.2
- [Commits](https://github.com/75lb/deep-merge/compare/v1.1.1...v1.1.2)

Updates `rollup` from 4.13.0 to 4.22.4
- [Release notes](https://github.com/rollup/rollup/releases)
- [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rollup/rollup/compare/v4.13.0...v4.22.4)

---
updated-dependencies:
- dependency-name: "@75lb/deep-merge"
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: rollup
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-24 12:24:15 +02:00
.devcontainer prettier 2024-03-19 11:27:57 +00:00
.github upgrade node to latest lts 2024-03-19 12:07:50 +00:00
examples add missing extensions to modules 2024-03-27 10:56:08 +00:00
src add missing extensions to modules 2024-03-27 10:56:08 +00:00
test Merge branch 'main' into fix-pasting-markdown-with-html 2024-03-20 09:38:47 +01:00
.eslintignore Lint configs 2020-02-20 14:24:32 -05:00
.eslintrc.json add missing extensions to modules 2024-03-27 10:56:08 +00:00
.gitignore Extract Markdown paste behaviors 2018-09-17 16:30:16 -06:00
CODEOWNERS move AOR to primer 2022-09-23 17:55:26 +01:00
LICENSE Extract Markdown paste behaviors 2018-09-17 16:30:16 -06:00
README.md Update readme 2022-09-21 08:20:10 +01:00
package-lock.json Bump the npm_and_yarn group with 2 updates (#101) 2024-09-24 12:24:15 +02:00
package.json use wtr and esbuild over karma and rollup 2024-03-19 11:27:44 +00:00
tsconfig.json use wtr and esbuild over karma and rollup 2024-03-19 11:27:44 +00:00
web-test-runner.config.js use wtr and esbuild over karma and rollup 2024-03-19 11:27:44 +00:00

README.md

Paste Markdown objects

  • Paste spreadsheet cells and HTML tables as a Markdown tables.
  • Paste URLs on selected text as Markdown links.
  • Paste text containing links as text containing Markdown links.
  • Paste image URLs as Markdown image links.
  • Paste markdown as markdown. See @github/quote-selection/Preserving markdown syntax for details.

Installation

$ npm install @github/paste-markdown

Usage

import {subscribe} from '@github/paste-markdown'

// Subscribe the behavior to the textarea.
subscribe(document.querySelector('textarea[data-paste-markdown]'))

Using a library like selector-observer, the behavior can automatically be applied to any element matching a selector.

import {observe} from 'selector-observer'
import {subscribe} from '@github/paste-markdown'

// Subscribe the behavior to all matching textareas.
observe('textarea[data-paste-markdown]', {subscribe})

Excluding <table>s

Some <table>s are not meant to be pasted as markdown; for example, a file content table with line numbers in a column. Use data-paste-markdown-skip to prevent it.

<table data-paste-markdown-skip>
  ...
</table>

Granular control for pasting as plain text

If you're wanting more granular support of pasting certain items as plain text by default, you can pass in the controls config at the subscribe level.

Our config support looks as follows:

import {subscribe} from '@github/paste-markdown'

// Subscribe the behavior to the textarea with pasting URL links as plain text by default.
subscribe(document.querySelector('textarea[data-paste-markdown]'), {defaultPlainTextPaste: {urlLinks: true}})

In this scenario above, pasting a URL over selected text will paste as plain text by default, but pasting a table will still paste as markdown by default.

Only the urlLinks param is currently supported.

If there is no config passed in, or attributes missing, this will always default to false, being the existing behavior.

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.