Skip to content

Commit

Permalink
sort reference links & add test cases for them
Browse files Browse the repository at this point in the history
  • Loading branch information
notslang committed Apr 17, 2016
1 parent 07432c4 commit 391bcf2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/index.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_ = require 'lodash'
fm = require 'front-matter'
marked = require 'marked'
yaml = require 'js-yaml'
Expand Down Expand Up @@ -246,6 +247,7 @@ module.exports = (dirtyMarkdown, options = {}) ->
url: value.href
title: value.title or null
)
links = _.sortBy(links, ['name', 'url'])

html = marked.parser(ast)

Expand Down
6 changes: 3 additions & 3 deletions test/expected/marked-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
See LICENSE for more info.
[badge]: http://badge.fury.io/js/marked
[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
[gfm]: https://help.github.com/articles/github-flavored-markdown
[gfmf]: http://github.github.com/github-flavored-markdown/
[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
[highlight]: https://github.com/isagalaev/highlight.js
[badge]: http://badge.fury.io/js/marked
[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
[tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
59 changes: 59 additions & 0 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,65 @@ describe 'inline grammar', ->
'<https://github.com/slang800/tidy-markdown>'
)

it 'should handle reference links', ->
tidyMdSnippet('''
[NPM version][npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''').should.equal('''
[NPM version][npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''')

it 'should handle shorthand reference links', ->
tidyMdSnippet('''
[npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''').should.equal('''
[npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''')

it 'should convert links to shorthand reference style', ->
tidyMdSnippet('''
[npm-url](https://npmjs.org/package/npms-analyzer)
[npm-url]: https://npmjs.org/package/npms-analyzer
''').should.equal('''
[npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''')

it 'should convert links to shorthand reference style', ->
tidyMdSnippet('''
[npm-url](https://npmjs.org/package/npms-analyzer)
[npm-url]: https://npmjs.org/package/npms-analyzer
''').should.equal('''
[npm-url]
[npm-url]: https://npmjs.org/package/npms-analyzer
''')

it 'should sort reference style links', ->
tidyMdSnippet('''
Visit [npm] or maybe [David DM][david-dm] or even [Travis]
[npm]: https://npmjs.org/package/npms-analyzer
[david-dm]: https://david-dm.org/npms-io/npms-analyzer
[travis]: https://travis-ci.org/npms-io/npms-analyzer
''').should.equal('''
Visit [npm] or maybe [David DM][david-dm] or even [Travis]
[david-dm]: https://david-dm.org/npms-io/npms-analyzer
[npm]: https://npmjs.org/package/npms-analyzer
[travis]: https://travis-ci.org/npms-io/npms-analyzer
''')

it 'should handle images', ->
tidyMdSnippet('![text](image.jpg)').should.equal('![text](image.jpg)')
tidyMdSnippet('![text]( image.jpg )').should.equal('![text](image.jpg)')
Expand Down

0 comments on commit 391bcf2

Please sign in to comment.