Skip to content

Commit

Permalink
Merge pull request #541 from ipfs-shipyard/fix/linkify-of-plain-text
Browse files Browse the repository at this point in the history
fix(linkify): do not wrap / ignore false-positives
  • Loading branch information
lidel committed Jul 26, 2018
2 parents a6583ae + 890ccd5 commit 04e3df7
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions add-on/src/contentScripts/linkifyDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ const PQueue = require('p-queue')

while ((match = urlRE.exec(txt))) {
link = await textToIpfsResource(match)
const textChunk = document.createTextNode(match[0])
if (span == null) {
// Create a span to hold the new text with links in it.
span = document.createElement('span')
span.className = 'linkifiedIpfsAddress'
}
if (link) {
const textChunk = document.createTextNode(match[0])
if (span == null) {
// Create a span to hold the new text with links in it.
span = document.createElement('span')
span.className = 'linkifiedIpfsAddress'
}
// put in text up to the link
span.appendChild(document.createTextNode(txt.substring(point, match.index)))
// create a link and put it in the span
Expand All @@ -185,13 +185,10 @@ const PQueue = require('p-queue')
a.setAttribute('href', link)
a.appendChild(textChunk)
span.appendChild(a)
} else {
// wrap text in span to exclude it from future processing
span.appendChild(textChunk)
// track insertion point
const replaceLength = match[0].length
point = match.index + replaceLength
}
// track insertion point
const replaceLength = match[0].length
point = match.index + replaceLength
}
if (span && node.parentNode) {
try {
Expand Down

0 comments on commit 04e3df7

Please sign in to comment.