Fix text content of Linkify ranges, add test.
This commit is contained in:
parent
5c327555d5
commit
b16e2205ed
@ -25,6 +25,10 @@ module.exports = (grunt) ->
|
|||||||
output = if parts2.length is 0 then '""' else parts2.join ' + '
|
output = if parts2.length is 0 then '""' else parts2.join ' + '
|
||||||
"(innerHTML: #{output})"
|
"(innerHTML: #{output})"
|
||||||
|
|
||||||
|
assert = (statement, objs...) ->
|
||||||
|
return '' unless grunt.config('pkg').tests_enabled
|
||||||
|
"throw new Error 'Assertion failed: ' + `#{JSON.stringify statement}` unless #{statement}"
|
||||||
|
|
||||||
# Project configuration.
|
# Project configuration.
|
||||||
grunt.initConfig
|
grunt.initConfig
|
||||||
pkg: grunt.file.readJSON 'package.json'
|
pkg: grunt.file.readJSON 'package.json'
|
||||||
@ -35,6 +39,7 @@ module.exports = (grunt) ->
|
|||||||
pkg = grunt.config 'pkg'
|
pkg = grunt.config 'pkg'
|
||||||
pkg.importHTML = importHTML
|
pkg.importHTML = importHTML
|
||||||
pkg.html = html
|
pkg.html = html
|
||||||
|
pkg.assert = assert
|
||||||
pkg.tests_enabled or= false
|
pkg.tests_enabled or= false
|
||||||
pkg
|
pkg
|
||||||
enumerable: true
|
enumerable: true
|
||||||
|
|||||||
@ -52,16 +52,20 @@ Linkify =
|
|||||||
|
|
||||||
endNode = saved
|
endNode = saved
|
||||||
{data} = saved
|
{data} = saved
|
||||||
word += data
|
|
||||||
{length} = data
|
|
||||||
|
|
||||||
if end = space.exec data
|
if end = space.exec data
|
||||||
# Set our snapshot and regex to start on this node at this position when the loop resumes
|
# Set our snapshot and regex to start on this node at this position when the loop resumes
|
||||||
|
word += data[...end.index]
|
||||||
test.lastIndex = length = end.index
|
test.lastIndex = length = end.index
|
||||||
i--
|
i--
|
||||||
break
|
break
|
||||||
|
else
|
||||||
|
{length} = data
|
||||||
|
word += data
|
||||||
|
|
||||||
links.push Linkify.makeRange node, endNode, index, length if Linkify.regString.exec word
|
if Linkify.regString.exec word
|
||||||
|
links.push Linkify.makeRange node, endNode, index, length
|
||||||
|
<%= assert('word is links[links.length-1].toString()') %>
|
||||||
|
|
||||||
break unless test.lastIndex and node is endNode
|
break unless test.lastIndex and node is endNode
|
||||||
|
|
||||||
@ -105,7 +109,7 @@ Linkify =
|
|||||||
# Clean start of range
|
# Clean start of range
|
||||||
i = text.search Linkify.regString
|
i = text.search Linkify.regString
|
||||||
|
|
||||||
if i
|
if i > 0
|
||||||
text = text.slice i
|
text = text.slice i
|
||||||
i-- while range.startOffset + i >= range.startContainer.data.length
|
i-- while range.startOffset + i >= range.startContainer.data.length
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user