@github/paste-markdown
Advanced tools
Comparing version 0.2.0 to 0.2.1
function insertText(textarea, text) { | ||
var point = textarea.selectionEnd; | ||
var beginning = textarea.value.substring(0, point); | ||
var remaining = textarea.value.substring(point); | ||
var newline = textarea.value === '' || beginning.match(/\n$/) ? '' : '\n'; | ||
textarea.value = beginning + newline + text + remaining; | ||
textarea.selectionStart = point + text.length; | ||
textarea.selectionEnd = point + text.length; | ||
const beginning = textarea.value.substring(0, textarea.selectionStart); | ||
const remaining = textarea.value.substring(textarea.selectionEnd); | ||
const newline = beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const textBeforeCursor = beginning + newline + text; | ||
textarea.value = textBeforeCursor + remaining; | ||
textarea.selectionStart = textBeforeCursor.length; | ||
textarea.selectionEnd = textarea.selectionStart; | ||
textarea.dispatchEvent(new CustomEvent('change', { | ||
@@ -28,37 +28,17 @@ bubbles: true, | ||
function onDrop(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (!transfer) return; | ||
if (hasFile(transfer)) return; | ||
if (!hasLink(transfer)) return; | ||
const links = extractLinks(transfer); | ||
if (!links.some(isImageLink)) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = links(transfer).map(linkify)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var link = _step.value; | ||
insertText(field, link); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
insertText(field, links.map(linkify).join('')); | ||
} | ||
function onDragover(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (transfer) transfer.dropEffect = 'link'; | ||
@@ -68,35 +48,15 @@ } | ||
function onPaste(event) { | ||
var transfer = event.clipboardData; | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasLink(transfer)) return; | ||
const links = extractLinks(transfer); | ||
if (!links.some(isImageLink)) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = links(transfer).map(linkify)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var link = _step2.value; | ||
insertText(field, link); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
insertText(field, links.map(linkify).join('')); | ||
} | ||
function linkify(link) { | ||
return isImageLink(link) ? "\n![](".concat(link, ")\n") : link; | ||
return isImageLink(link) ? `\n![](${link})\n` : link; | ||
} | ||
@@ -112,9 +72,10 @@ | ||
function links(transfer) { | ||
function extractLinks(transfer) { | ||
return (transfer.getData('text/uri-list') || '').split('\r\n'); | ||
} | ||
const IMAGE_RE = /\.(gif|png|jpe?g)$/i; | ||
function isImageLink(url) { | ||
var ext = url.split('.').pop().toLowerCase(); | ||
return ['gif', 'png', 'jpg', 'jpeg'].indexOf(ext) > -1; | ||
return IMAGE_RE.test(url); | ||
} | ||
@@ -134,10 +95,10 @@ | ||
function onDrop$1(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (!transfer) return; | ||
if (hasFile$1(transfer)) return; | ||
var table = hasTable(transfer); | ||
const table = hasTable(transfer); | ||
if (!table) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
@@ -150,3 +111,3 @@ if (field instanceof HTMLTextAreaElement) { | ||
function onDragover$1(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (transfer) transfer.dropEffect = 'copy'; | ||
@@ -157,7 +118,7 @@ } | ||
if (!event.clipboardData) return; | ||
var table = hasTable(event.clipboardData); | ||
const table = hasTable(event.clipboardData); | ||
if (!table) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
@@ -174,4 +135,4 @@ if (field instanceof HTMLTextAreaElement) { | ||
function columnText(column) { | ||
var noBreakSpace = "\xA0"; | ||
var text = column.textContent.trim().replace(/\|/g, '\\|').replace(/\n/g, ' '); | ||
const noBreakSpace = '\u00A0'; | ||
const text = column.textContent.trim().replace(/\|/g, '\\|').replace(/\n/g, ' '); | ||
return text || noBreakSpace; | ||
@@ -185,16 +146,14 @@ } | ||
function tableMarkdown(node) { | ||
var rows = Array.from(node.querySelectorAll('tr')); | ||
var headers = tableHeaders(rows.shift()); | ||
var spacers = headers.map(function () { | ||
return '--'; | ||
}); | ||
var header = "".concat(headers.join(' | '), "\n").concat(spacers.join(' | '), "\n"); | ||
var body = rows.map(function (row) { | ||
const rows = Array.from(node.querySelectorAll('tr')); | ||
const headers = tableHeaders(rows.shift()); | ||
const spacers = headers.map(() => '--'); | ||
const header = `${headers.join(' | ')}\n${spacers.join(' | ')}\n`; | ||
const body = rows.map(row => { | ||
return Array.from(row.querySelectorAll('td')).map(columnText).join(' | '); | ||
}).join('\n'); | ||
return "\n".concat(header).concat(body, "\n\n"); | ||
return `\n${header}${body}\n\n`; | ||
} | ||
function parseTable(html) { | ||
var el = document.createElement('div'); | ||
const el = document.createElement('div'); | ||
el.innerHTML = html; | ||
@@ -206,5 +165,5 @@ return el.querySelector('table'); | ||
if (Array.from(transfer.types).indexOf('text/html') === -1) return; | ||
var html = transfer.getData('text/html'); | ||
const html = transfer.getData('text/html'); | ||
if (!/<table/i.test(html)) return; | ||
var table = parseTable(html); | ||
const table = parseTable(html); | ||
if (!table) return; // Edge copies the surrounding table from our issue comment text. | ||
@@ -224,7 +183,7 @@ | ||
function onPaste$2(event) { | ||
var transfer = event.clipboardData; | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasMarkdown(transfer)) return; | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var text = transfer.getData('text/x-gfm'); | ||
const text = transfer.getData('text/x-gfm'); | ||
if (!text) return; | ||
@@ -245,3 +204,3 @@ event.stopPropagation(); | ||
return { | ||
unsubscribe: function unsubscribe() { | ||
unsubscribe: () => { | ||
uninstall$1(el); | ||
@@ -248,0 +207,0 @@ uninstall(el); |
@@ -8,9 +8,9 @@ (function (global, factory) { | ||
function insertText(textarea, text) { | ||
var point = textarea.selectionEnd; | ||
var beginning = textarea.value.substring(0, point); | ||
var remaining = textarea.value.substring(point); | ||
var newline = textarea.value === '' || beginning.match(/\n$/) ? '' : '\n'; | ||
textarea.value = beginning + newline + text + remaining; | ||
textarea.selectionStart = point + text.length; | ||
textarea.selectionEnd = point + text.length; | ||
const beginning = textarea.value.substring(0, textarea.selectionStart); | ||
const remaining = textarea.value.substring(textarea.selectionEnd); | ||
const newline = beginning.length === 0 || beginning.match(/\n$/) ? '' : '\n'; | ||
const textBeforeCursor = beginning + newline + text; | ||
textarea.value = textBeforeCursor + remaining; | ||
textarea.selectionStart = textBeforeCursor.length; | ||
textarea.selectionEnd = textarea.selectionStart; | ||
textarea.dispatchEvent(new CustomEvent('change', { | ||
@@ -35,37 +35,17 @@ bubbles: true, | ||
function onDrop(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (!transfer) return; | ||
if (hasFile(transfer)) return; | ||
if (!hasLink(transfer)) return; | ||
const links = extractLinks(transfer); | ||
if (!links.some(isImageLink)) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = links(transfer).map(linkify)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var link = _step.value; | ||
insertText(field, link); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
insertText(field, links.map(linkify).join('')); | ||
} | ||
function onDragover(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (transfer) transfer.dropEffect = 'link'; | ||
@@ -75,35 +55,15 @@ } | ||
function onPaste(event) { | ||
var transfer = event.clipboardData; | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasLink(transfer)) return; | ||
const links = extractLinks(transfer); | ||
if (!links.some(isImageLink)) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = links(transfer).map(linkify)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var link = _step2.value; | ||
insertText(field, link); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
insertText(field, links.map(linkify).join('')); | ||
} | ||
function linkify(link) { | ||
return isImageLink(link) ? "\n![](".concat(link, ")\n") : link; | ||
return isImageLink(link) ? `\n![](${link})\n` : link; | ||
} | ||
@@ -119,9 +79,10 @@ | ||
function links(transfer) { | ||
function extractLinks(transfer) { | ||
return (transfer.getData('text/uri-list') || '').split('\r\n'); | ||
} | ||
const IMAGE_RE = /\.(gif|png|jpe?g)$/i; | ||
function isImageLink(url) { | ||
var ext = url.split('.').pop().toLowerCase(); | ||
return ['gif', 'png', 'jpg', 'jpeg'].indexOf(ext) > -1; | ||
return IMAGE_RE.test(url); | ||
} | ||
@@ -141,10 +102,10 @@ | ||
function onDrop$1(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (!transfer) return; | ||
if (hasFile$1(transfer)) return; | ||
var table = hasTable(transfer); | ||
const table = hasTable(transfer); | ||
if (!table) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
@@ -157,3 +118,3 @@ if (field instanceof HTMLTextAreaElement) { | ||
function onDragover$1(event) { | ||
var transfer = event.dataTransfer; | ||
const transfer = event.dataTransfer; | ||
if (transfer) transfer.dropEffect = 'copy'; | ||
@@ -164,7 +125,7 @@ } | ||
if (!event.clipboardData) return; | ||
var table = hasTable(event.clipboardData); | ||
const table = hasTable(event.clipboardData); | ||
if (!table) return; | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
@@ -181,4 +142,4 @@ if (field instanceof HTMLTextAreaElement) { | ||
function columnText(column) { | ||
var noBreakSpace = "\xA0"; | ||
var text = column.textContent.trim().replace(/\|/g, '\\|').replace(/\n/g, ' '); | ||
const noBreakSpace = '\u00A0'; | ||
const text = column.textContent.trim().replace(/\|/g, '\\|').replace(/\n/g, ' '); | ||
return text || noBreakSpace; | ||
@@ -192,16 +153,14 @@ } | ||
function tableMarkdown(node) { | ||
var rows = Array.from(node.querySelectorAll('tr')); | ||
var headers = tableHeaders(rows.shift()); | ||
var spacers = headers.map(function () { | ||
return '--'; | ||
}); | ||
var header = "".concat(headers.join(' | '), "\n").concat(spacers.join(' | '), "\n"); | ||
var body = rows.map(function (row) { | ||
const rows = Array.from(node.querySelectorAll('tr')); | ||
const headers = tableHeaders(rows.shift()); | ||
const spacers = headers.map(() => '--'); | ||
const header = `${headers.join(' | ')}\n${spacers.join(' | ')}\n`; | ||
const body = rows.map(row => { | ||
return Array.from(row.querySelectorAll('td')).map(columnText).join(' | '); | ||
}).join('\n'); | ||
return "\n".concat(header).concat(body, "\n\n"); | ||
return `\n${header}${body}\n\n`; | ||
} | ||
function parseTable(html) { | ||
var el = document.createElement('div'); | ||
const el = document.createElement('div'); | ||
el.innerHTML = html; | ||
@@ -213,5 +172,5 @@ return el.querySelector('table'); | ||
if (Array.from(transfer.types).indexOf('text/html') === -1) return; | ||
var html = transfer.getData('text/html'); | ||
const html = transfer.getData('text/html'); | ||
if (!/<table/i.test(html)) return; | ||
var table = parseTable(html); | ||
const table = parseTable(html); | ||
if (!table) return; // Edge copies the surrounding table from our issue comment text. | ||
@@ -231,7 +190,7 @@ | ||
function onPaste$2(event) { | ||
var transfer = event.clipboardData; | ||
const transfer = event.clipboardData; | ||
if (!transfer || !hasMarkdown(transfer)) return; | ||
var field = event.currentTarget; | ||
const field = event.currentTarget; | ||
if (!(field instanceof HTMLTextAreaElement)) return; | ||
var text = transfer.getData('text/x-gfm'); | ||
const text = transfer.getData('text/x-gfm'); | ||
if (!text) return; | ||
@@ -252,3 +211,3 @@ event.stopPropagation(); | ||
return { | ||
unsubscribe: function unsubscribe() { | ||
unsubscribe: () => { | ||
uninstall$1(el); | ||
@@ -255,0 +214,0 @@ uninstall(el); |
{ | ||
"name": "@github/paste-markdown", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Paste spreadsheet cells as a Markdown table.", | ||
@@ -10,3 +10,3 @@ "repository": "github/paste-markdown", | ||
"clean": "rm -rf dist", | ||
"lint": "eslint src/ && flow check", | ||
"lint": "eslint . && flow check", | ||
"prebuild": "npm run clean && npm run lint && mkdir dist", | ||
@@ -26,7 +26,5 @@ "build": "rollup -c && cp src/index.js.flow dist/index.umd.js.flow && cp src/index.js.flow dist/index.esm.js.flow", | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.4", | ||
"@babel/preset-env": "^7.3.4", | ||
"@babel/preset-flow": "^7.0.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-preset-github": "^3.2.0", | ||
"eslint": "^5.14.1", | ||
@@ -45,3 +43,6 @@ "eslint-plugin-github": "^1.10.0", | ||
"parser": "babel-eslint" | ||
} | ||
}, | ||
"eslintIgnore": [ | ||
"dist/" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
15292
354
1