diff --git a/lib/tidy-inline-markdown.coffee b/lib/tidy-inline-markdown.coffee index 893e562..cc3ece9 100644 --- a/lib/tidy-inline-markdown.coffee +++ b/lib/tidy-inline-markdown.coffee @@ -20,12 +20,18 @@ tidyInlineMarkdown = (token) -> .replace CODE_REGEX, (m, code) -> delimitCode(code, '`') .replace IMG_REGEX, (m, url='', alt='', title) -> if title? - url += " \"#{title.replace /\\|"/g, (m) -> "\\#{m}"}\"" + title = title.replace /\\|"/g, (m) -> "\\#{m}" + url += " \"#{title}\"" return "![#{alt}](#{url})" .replace LINK_REGEX, (m, url='', title, text='') -> if title? - url += " \"#{title.replace /\\|"/g, (m) -> "\\#{m}"}\"" - return "[#{text}](#{url})" + title = title.replace /\\|"/g, (m) -> "\\#{m}" + url += " \"#{title}\"" + + if url is text and url isnt '' + return "<#{url}>" + else + return "[#{text}](#{url})" token.text = htmlEntities.decode(token.text) return token diff --git a/test/index.coffee b/test/index.coffee index fd3d8e1..32a2f4d 100644 --- a/test/index.coffee +++ b/test/index.coffee @@ -260,6 +260,16 @@ describe 'inline grammar', -> tidyMdSnippet('[](#anchor)').should.equal('[](#anchor)') tidyMdSnippet('[]()').should.equal('[]()') tidyMdSnippet('[](#anchor "Title")').should.equal('[](#anchor "Title")') + tidyMdSnippet( + 'https://github.com/slang800/tidy-markdown' + ).should.equal( + '' + ) + tidyMdSnippet( + '' + ).should.equal( + '' + ) it 'should handle images', -> tidyMdSnippet('![text](image.jpg)').should.equal('![text](image.jpg)')