Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@github/paste-markdown

Package Overview
Dependencies
Maintainers
19
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/paste-markdown - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

dist/paste-markdown-html.d.ts

3

dist/index.d.ts

@@ -0,1 +1,2 @@

import { install as installHTML, uninstall as uninstallHTML } from './paste-markdown-html';
import { install as installImageLink, uninstall as uninstallImageLink } from './paste-markdown-image-link';

@@ -9,2 +10,2 @@ import { install as installLink, uninstall as uninstallLink } from './paste-markdown-link';

declare function subscribe(el: HTMLElement): Subscription;
export { subscribe, installImageLink, installLink, installTable, installText, uninstallImageLink, uninstallTable, uninstallLink, uninstallText };
export { subscribe, installHTML, installImageLink, installLink, installTable, installText, uninstallHTML, uninstallImageLink, uninstallTable, uninstallLink, uninstallText };

@@ -33,2 +33,60 @@ function insertText(textarea, text) {

function install$4(el) {
el.addEventListener('paste', onPaste$4);
}
function uninstall$4(el) {
el.removeEventListener('paste', onPaste$4);
}
function onPaste$4(event) {
const transfer = event.clipboardData;
if (!transfer || !hasHTML(transfer))
return;
const field = event.currentTarget;
if (!(field instanceof HTMLTextAreaElement))
return;
let text = transfer.getData('text/plain');
const textHTML = transfer.getData('text/html');
if (!textHTML)
return;
text = text.trim();
if (!text)
return;
const parser = new DOMParser();
const doc = parser.parseFromString(textHTML, 'text/html');
const a = doc.getElementsByTagName('a');
const markdown = transform(a, text, linkify$2);
if (markdown === text)
return;
event.stopPropagation();
event.preventDefault();
insertText(field, markdown);
}
function transform(elements, text, transformer, ...args) {
const markdownParts = [];
for (const element of elements) {
const textContent = element.textContent || '';
const { part, index } = trimAfter(text, textContent);
markdownParts.push(part.replace(textContent, transformer(element, args)));
text = text.slice(index);
}
markdownParts.push(text);
return markdownParts.join('');
}
function trimAfter(text, search = '') {
let index = text.indexOf(search);
if (index === -1)
return { part: '', index };
index += search.length;
return {
part: text.substring(0, index),
index
};
}
function hasHTML(transfer) {
return transfer.types.includes('text/html');
}
function linkify$2(element) {
return `[${element.textContent}](${element.href})`;
}
function install$3(el) {

@@ -262,5 +320,7 @@ el.addEventListener('dragover', onDragover$1);

install(el);
install$4(el);
return {
unsubscribe: () => {
uninstall$1(el);
uninstall$4(el);
uninstall$3(el);

@@ -273,2 +333,2 @@ uninstall$2(el);

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 };
export { install$4 as installHTML, install$3 as installImageLink, install$2 as installLink, install$1 as installTable, install as installText, subscribe, uninstall$4 as uninstallHTML, uninstall$3 as uninstallImageLink, uninstall$2 as uninstallLink, uninstall$1 as uninstallTable, uninstall as uninstallText };

@@ -39,2 +39,60 @@ (function (global, factory) {

function install$4(el) {
el.addEventListener('paste', onPaste$4);
}
function uninstall$4(el) {
el.removeEventListener('paste', onPaste$4);
}
function onPaste$4(event) {
const transfer = event.clipboardData;
if (!transfer || !hasHTML(transfer))
return;
const field = event.currentTarget;
if (!(field instanceof HTMLTextAreaElement))
return;
let text = transfer.getData('text/plain');
const textHTML = transfer.getData('text/html');
if (!textHTML)
return;
text = text.trim();
if (!text)
return;
const parser = new DOMParser();
const doc = parser.parseFromString(textHTML, 'text/html');
const a = doc.getElementsByTagName('a');
const markdown = transform(a, text, linkify$2);
if (markdown === text)
return;
event.stopPropagation();
event.preventDefault();
insertText(field, markdown);
}
function transform(elements, text, transformer, ...args) {
const markdownParts = [];
for (const element of elements) {
const textContent = element.textContent || '';
const { part, index } = trimAfter(text, textContent);
markdownParts.push(part.replace(textContent, transformer(element, args)));
text = text.slice(index);
}
markdownParts.push(text);
return markdownParts.join('');
}
function trimAfter(text, search = '') {
let index = text.indexOf(search);
if (index === -1)
return { part: '', index };
index += search.length;
return {
part: text.substring(0, index),
index
};
}
function hasHTML(transfer) {
return transfer.types.includes('text/html');
}
function linkify$2(element) {
return `[${element.textContent}](${element.href})`;
}
function install$3(el) {

@@ -268,5 +326,7 @@ el.addEventListener('dragover', onDragover$1);

install(el);
install$4(el);
return {
unsubscribe: () => {
uninstall$1(el);
uninstall$4(el);
uninstall$3(el);

@@ -279,2 +339,3 @@ uninstall$2(el);

exports.installHTML = install$4;
exports.installImageLink = install$3;

@@ -285,2 +346,3 @@ exports.installLink = install$2;

exports.subscribe = subscribe;
exports.uninstallHTML = uninstall$4;
exports.uninstallImageLink = uninstall$3;

@@ -287,0 +349,0 @@ exports.uninstallLink = uninstall$2;

{
"name": "@github/paste-markdown",
"version": "1.1.1",
"version": "1.2.0",
"description": "Paste spreadsheet cells as a Markdown table.",

@@ -5,0 +5,0 @@ "repository": "github/paste-markdown",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc