@github/paste-markdown
Advanced tools
Comparing version 0.3.4 to 1.0.0
@@ -0,5 +1,9 @@ | ||
import { install as installImageLink, uninstall as uninstallImageLink } from './paste-markdown-image-link'; | ||
import { install as installLink, uninstall as uninstallLink } from './paste-markdown-link'; | ||
import { install as installTable, uninstall as uninstallTable } from './paste-markdown-table'; | ||
import { install as installText, uninstall as uninstallText } from './paste-markdown-text'; | ||
interface Subscription { | ||
unsubscribe: () => void; | ||
} | ||
export default function subscribe(el: HTMLElement): Subscription; | ||
export {}; | ||
declare function subscribe(el: HTMLElement): Subscription; | ||
export { subscribe, installImageLink, installLink, installTable, installText, uninstallImageLink, uninstallTable, uninstallLink, uninstallText }; |
@@ -1,5 +0,5 @@ | ||
function insertText(textarea, text) { | ||
function insertText(textarea, text, options = { addNewline: true }) { | ||
const beginning = textarea.value.substring(0, textarea.selectionStart || 0); | ||
const remaining = textarea.value.substring(textarea.selectionEnd || 0); | ||
const newline = beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const newline = !options.addNewline || beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const textBeforeCursor = beginning + newline + text; | ||
@@ -16,11 +16,11 @@ textarea.value = textBeforeCursor + remaining; | ||
function install$2(el) { | ||
function install$3(el) { | ||
el.addEventListener('dragover', onDragover$1); | ||
el.addEventListener('drop', onDrop$1); | ||
el.addEventListener('paste', onPaste$2); | ||
el.addEventListener('paste', onPaste$3); | ||
} | ||
function uninstall$2(el) { | ||
function uninstall$3(el) { | ||
el.removeEventListener('dragover', onDragover$1); | ||
el.removeEventListener('drop', onDrop$1); | ||
el.removeEventListener('paste', onPaste$2); | ||
el.removeEventListener('paste', onPaste$3); | ||
} | ||
@@ -43,3 +43,3 @@ function onDrop$1(event) { | ||
return; | ||
insertText(field, links.map(linkify).join('')); | ||
insertText(field, links.map(linkify$1).join('')); | ||
} | ||
@@ -51,3 +51,3 @@ function onDragover$1(event) { | ||
} | ||
function onPaste$2(event) { | ||
function onPaste$3(event) { | ||
const transfer = event.clipboardData; | ||
@@ -64,5 +64,5 @@ if (!transfer || !hasLink(transfer)) | ||
return; | ||
insertText(field, links.map(linkify).join('')); | ||
insertText(field, links.map(linkify$1).join('')); | ||
} | ||
function linkify(link) { | ||
function linkify$1(link) { | ||
return isImageLink(link) ? `\n\n` : link; | ||
@@ -84,2 +84,45 @@ } | ||
function install$2(el) { | ||
el.addEventListener('paste', onPaste$2); | ||
} | ||
function uninstall$2(el) { | ||
el.removeEventListener('paste', onPaste$2); | ||
} | ||
function onPaste$2(event) { | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasPlainText(transfer)) | ||
return; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) | ||
return; | ||
const text = transfer.getData('text/plain'); | ||
if (!text) | ||
return; | ||
if (isWithinLink(field)) | ||
return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
const selectedText = field.value.substring(field.selectionStart, field.selectionEnd); | ||
insertText(field, linkify(selectedText, text), { addNewline: false }); | ||
} | ||
function hasPlainText(transfer) { | ||
return Array.from(transfer.types).includes('text/plain'); | ||
} | ||
function isWithinLink(textarea) { | ||
const selectionStart = textarea.selectionStart || 0; | ||
if (selectionStart > 1) { | ||
const previousChars = textarea.value.substring(selectionStart - 2, selectionStart); | ||
return previousChars === ']('; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
function linkify(selectedText, text) { | ||
return selectedText.length && isURL(text) ? `[${selectedText}](${text})` : text; | ||
} | ||
function isURL(url) { | ||
return /^https?:\/\//i.test(url); | ||
} | ||
function install$1(el) { | ||
@@ -197,2 +240,3 @@ el.addEventListener('dragover', onDragover); | ||
install$1(el); | ||
install$3(el); | ||
install$2(el); | ||
@@ -203,2 +247,3 @@ install(el); | ||
uninstall$1(el); | ||
uninstall$3(el); | ||
uninstall$2(el); | ||
@@ -210,2 +255,2 @@ uninstall(el); | ||
export default subscribe; | ||
export { install$3 as installImageLink, install$2 as installLink, install$1 as installTable, install as installText, subscribe, uninstall$3 as uninstallImageLink, uninstall$2 as uninstallLink, uninstall$1 as uninstallTable, uninstall as uninstallText }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['paste-markdown'] = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['paste-markdown'] = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
function insertText(textarea, text) { | ||
function insertText(textarea, text, options = { addNewline: true }) { | ||
const beginning = textarea.value.substring(0, textarea.selectionStart || 0); | ||
const remaining = textarea.value.substring(textarea.selectionEnd || 0); | ||
const newline = beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const newline = !options.addNewline || beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const textBeforeCursor = beginning + newline + text; | ||
@@ -22,11 +22,11 @@ textarea.value = textBeforeCursor + remaining; | ||
function install$2(el) { | ||
function install$3(el) { | ||
el.addEventListener('dragover', onDragover$1); | ||
el.addEventListener('drop', onDrop$1); | ||
el.addEventListener('paste', onPaste$2); | ||
el.addEventListener('paste', onPaste$3); | ||
} | ||
function uninstall$2(el) { | ||
function uninstall$3(el) { | ||
el.removeEventListener('dragover', onDragover$1); | ||
el.removeEventListener('drop', onDrop$1); | ||
el.removeEventListener('paste', onPaste$2); | ||
el.removeEventListener('paste', onPaste$3); | ||
} | ||
@@ -49,3 +49,3 @@ function onDrop$1(event) { | ||
return; | ||
insertText(field, links.map(linkify).join('')); | ||
insertText(field, links.map(linkify$1).join('')); | ||
} | ||
@@ -57,3 +57,3 @@ function onDragover$1(event) { | ||
} | ||
function onPaste$2(event) { | ||
function onPaste$3(event) { | ||
const transfer = event.clipboardData; | ||
@@ -70,5 +70,5 @@ if (!transfer || !hasLink(transfer)) | ||
return; | ||
insertText(field, links.map(linkify).join('')); | ||
insertText(field, links.map(linkify$1).join('')); | ||
} | ||
function linkify(link) { | ||
function linkify$1(link) { | ||
return isImageLink(link) ? `\n\n` : link; | ||
@@ -90,2 +90,45 @@ } | ||
function install$2(el) { | ||
el.addEventListener('paste', onPaste$2); | ||
} | ||
function uninstall$2(el) { | ||
el.removeEventListener('paste', onPaste$2); | ||
} | ||
function onPaste$2(event) { | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasPlainText(transfer)) | ||
return; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) | ||
return; | ||
const text = transfer.getData('text/plain'); | ||
if (!text) | ||
return; | ||
if (isWithinLink(field)) | ||
return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
const selectedText = field.value.substring(field.selectionStart, field.selectionEnd); | ||
insertText(field, linkify(selectedText, text), { addNewline: false }); | ||
} | ||
function hasPlainText(transfer) { | ||
return Array.from(transfer.types).includes('text/plain'); | ||
} | ||
function isWithinLink(textarea) { | ||
const selectionStart = textarea.selectionStart || 0; | ||
if (selectionStart > 1) { | ||
const previousChars = textarea.value.substring(selectionStart - 2, selectionStart); | ||
return previousChars === ']('; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
function linkify(selectedText, text) { | ||
return selectedText.length && isURL(text) ? `[${selectedText}](${text})` : text; | ||
} | ||
function isURL(url) { | ||
return /^https?:\/\//i.test(url); | ||
} | ||
function install$1(el) { | ||
@@ -203,2 +246,3 @@ el.addEventListener('dragover', onDragover); | ||
install$1(el); | ||
install$3(el); | ||
install$2(el); | ||
@@ -209,2 +253,3 @@ install(el); | ||
uninstall$1(el); | ||
uninstall$3(el); | ||
uninstall$2(el); | ||
@@ -216,4 +261,14 @@ uninstall(el); | ||
return subscribe; | ||
exports.installImageLink = install$3; | ||
exports.installLink = install$2; | ||
exports.installTable = install$1; | ||
exports.installText = install; | ||
exports.subscribe = subscribe; | ||
exports.uninstallImageLink = uninstall$3; | ||
exports.uninstallLink = uninstall$2; | ||
exports.uninstallTable = uninstall$1; | ||
exports.uninstallText = uninstall; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
{ | ||
"name": "@github/paste-markdown", | ||
"version": "0.3.4", | ||
"version": "1.0.0", | ||
"description": "Paste spreadsheet cells as a Markdown table.", | ||
@@ -33,5 +33,5 @@ "repository": "github/paste-markdown", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.25.0", | ||
"eslint-plugin-github": "^4.1.3", | ||
"karma": "^6.3.2", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-github": "^4.3.0", | ||
"karma": "^6.3.4", | ||
"karma-chai": "^0.1.0", | ||
@@ -41,7 +41,7 @@ "karma-chrome-launcher": "^3.1.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"mocha": "^8.3.2", | ||
"rollup": "^2.46.0", | ||
"mocha": "^9.1.1", | ||
"rollup": "^2.56.3", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typescript": "^4.2.4" | ||
"typescript": "^4.4.3" | ||
} | ||
} |
# Paste Markdown objects | ||
- Paste spreadsheet cells and HTML tables as a Markdown tables. | ||
- Paste URLs on selected text as Markdown links. | ||
- Paste image URLs as Markdown image links. | ||
@@ -16,3 +17,3 @@ - Paste markdown as markdown. See [`@github/quote-selection`/Preserving markdown syntax](https://github.com/github/quote-selection/tree/9ae5f88f5bc3021f51d2dc9981eca83ce7cfe04f#preserving-markdown-syntax) for details. | ||
```js | ||
import subscribe from '@github/paste-markdown' | ||
import {subscribe} from '@github/paste-markdown' | ||
@@ -30,3 +31,3 @@ // Subscribe the behavior to the textarea. | ||
import {observe} from 'selector-observer' | ||
import subscribe from '@github/paste-markdown' | ||
import {subscribe} from '@github/paste-markdown' | ||
@@ -33,0 +34,0 @@ // Subscribe the behavior to all matching textareas. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21591
508
1
56
1