Skip to content

Commit

Permalink
fix(linkify): do not wrap ignore false-positives
Browse files Browse the repository at this point in the history
Closes #539
  • Loading branch information
lidel committed Jul 25, 2018
1 parent a6583ae commit 890ccd5
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 890ccd5

Please sign in to comment.