-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from aepfli/making_anchor_detection_configurable
Reintroduce anchor detection as configurable step
- Loading branch information
Showing
3 changed files
with
61 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,88 +6,86 @@ var markdownLinkExtractor = require('../'); | |
describe('markdown-link-extractor', function () { | ||
|
||
it('should return an empty array when no links are present', function () { | ||
var links = markdownLinkExtractor('No links here'); | ||
var { links } = markdownLinkExtractor('No links here'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(0); | ||
}); | ||
|
||
it('should extract links with emojis', function () { | ||
var links = markdownLinkExtractor('**[📣 Foo!](https://www.example.com)**'); | ||
var { links } = markdownLinkExtractor('**[📣 Foo!](https://www.example.com)**'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('https://www.example.com'); | ||
}); | ||
|
||
it('should extract a link in a [tag](http://example.com)', function () { | ||
var links = markdownLinkExtractor('[example](http://www.example.com)'); | ||
var { links } = markdownLinkExtractor('[example](http://www.example.com)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('http://www.example.com'); | ||
}); | ||
|
||
it('should extract a hash link in [foobar](#foobar)', function () { | ||
var links = markdownLinkExtractor('[foobar](#foobar)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('#foobar'); | ||
}); | ||
|
||
it('should extract a link from inline html <a href="http://foo.bar.test">foo</a>', function () { | ||
var links = markdownLinkExtractor('<a href="http://foo.bar.test">foo</a>'); | ||
var { links } = markdownLinkExtractor('<a href="http://foo.bar.test">foo</a>'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('http://foo.bar.test'); | ||
}); | ||
|
||
it('should extract mailto: link from <[email protected]>', function () { | ||
var links = markdownLinkExtractor('<[email protected]>)'); | ||
var { links } = markdownLinkExtractor('<[email protected]>)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('mailto:[email protected]'); | ||
}); | ||
|
||
it('should extract a link in a with escaped braces [tag](http://example.com\(1\))', function () { | ||
var links = markdownLinkExtractor('[XMLHttpRequest](http://msdn.microsoft.com/library/ie/ms535874\\(v=vs.85\\).aspx)'); | ||
var { links } = markdownLinkExtractor('[XMLHttpRequest](http://msdn.microsoft.com/library/ie/ms535874\\(v=vs.85\\).aspx)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('http://msdn.microsoft.com/library/ie/ms535874(v=vs.85).aspx'); | ||
}); | ||
|
||
it('should extract an image link in a ![tag](http://example.com/image.jpg)', function () { | ||
var links = markdownLinkExtractor('![example](http://www.example.com/image.jpg)'); | ||
var { links } = markdownLinkExtractor('![example](http://www.example.com/image.jpg)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('http://www.example.com/image.jpg'); | ||
}); | ||
|
||
it('should extract an image link in a ![tag](foo/image.jpg)', function () { | ||
var links = markdownLinkExtractor('![example](foo/image.jpg)'); | ||
var { links } = markdownLinkExtractor('![example](foo/image.jpg)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('foo/image.jpg'); | ||
}); | ||
|
||
it('should extract two image links', function () { | ||
var links = markdownLinkExtractor('![img](http://www.example.test/hello.jpg) ![img](hello.jpg)'); | ||
var { links } = markdownLinkExtractor('![img](http://www.example.test/hello.jpg) ![img](hello.jpg)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(2); | ||
expect(links[0]).to.be('http://www.example.test/hello.jpg'); | ||
expect(links[1]).to.be('hello.jpg'); | ||
}); | ||
|
||
it('should extract a bare link http://example.com', function () { | ||
var links = markdownLinkExtractor('This is a link: http://www.example.com'); | ||
var { links } = markdownLinkExtractor('This is a link: http://www.example.com'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(1); | ||
expect(links[0]).to.be('http://www.example.com'); | ||
}); | ||
|
||
it('should extract multiple links', function () { | ||
var links = markdownLinkExtractor('This is an [example](http://www.example.com). Hope it [works](http://www.example.com/works)'); | ||
var { links } = markdownLinkExtractor('This is an [example](http://www.example.com). Hope it [works](http://www.example.com/works)'); | ||
expect(links).to.be.an('array'); | ||
expect(links).to.have.length(2); | ||
expect(links[0]).to.be('http://www.example.com'); | ||
expect(links[1]).to.be('http://www.example.com/works'); | ||
}); | ||
|
||
}); | ||
it('should collect anchor tags', function () { | ||
var { anchors } = markdownLinkExtractor('# foo\n# foo', true); | ||
expect(anchors).to.eql(['#foo','#foo-1']); | ||
}); | ||
|
||
}); |