GithubHelp home page GithubHelp logo

alexcorvi / anchorme.js Goto Github PK

View Code? Open in Web Editor NEW
559.0 8.0 63.0 1.62 MB

Tiny, fast, efficient, feature rich Javascript library to detect links / URLs / Emails in text and convert them to clickable HTML anchor links

Home Page: http://alexcorvi.github.io/anchorme.js/

License: MIT License

JavaScript 1.49% HTML 18.30% TypeScript 80.21%
text-to-url url-detection email-validation url-validation urls

anchorme.js's People

Contributors

alexcorvi avatar ali-saleem avatar azagniotov avatar chrisoelmueller avatar davidschlachter avatar faizanahemad avatar harryburns avatar ionogy avatar jack-works avatar jessidhia avatar kmsheng avatar sebamarynissen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anchorme.js's Issues

Rendering does not consider links already within an anchor

Issue:
When text is run through the anchorme method multiple times it will nest links within the existing links.

Expected result:
Parser recognizes that the link is already within an anchor tag and does not generate a nested link.

Steps to recreate:
Run this text through anchorme:
Initial: http://google.com
1st render: <a href="http://google.com" >http://google.com</a>
2nd render: <a href="http://google.com" ><a href="http://google.com" >http://google.com</a></a>

Anchor tag recursion

There seems to be an issue by having an anchor tag with the URL as its content. We're using anchorme with a rich text editing library, which insert an anchor html element with the content being a URL string:
<a href="http://www.google.com">http://www.google.com</a>

Anchorme will place another tag inside the existing tag. This will recurse each time the string is parsed.

I realise that the library's core function is to find URL strings and wrap them, so this might not be the best use for it or even an issue really, but is there a (quick) workaround for this issue?
Maybe an option like ignoreUrlsInTags could be added?

Using this to parse front end, like ng-repeat?

Is there any way to use this without having to convert the original variable to a anchorme.js variable? Say for example when using angularJS and jg-repeat, is there any way to use it on text as it's being displayed?

Removing whitespaces

If you input this:
(text text..) text text text text text,
you get this
(text text..)texttext text text text

Decimal IP detection

Currently the library doesn't support decimal IPs. such as 2130706433 (which is basically 127.0.0.1).

I can't really imagine a real world use case for this library where the decimal IP detection would be needed. So if implemented, I might disable it by default, and/or enable it only when port is defined.

The implementation however is rather simple:

function decimalToIP(decimal:number):string{
     return ((decimal>>24)&0xff) + '.' +
     ((decimal>>16)&0xff) + '.' + 
     ((decimal>>8)&0xff) + '.' +
     (decimal&0xff);
}

Work around extensibility

The tests should extensions, with few builtin extensions like url, email, and ip.

This will allow projects to use anchorme for all their anchor-linking tasks such as hashtags and mentions ... etc

Wrong option "email"

According to source, option should be plural (emails). Please consider updating the documentation (readme file).

Also, there's an option "TLDs" which is not explained (should it be?)

clean up some left overs

After refractoring to typescript lot of things changed on how the library splits up text, identifies link and skips HTML.

I forgot to remove some lines that don't do anything anymore:

Single hostname isn't linked

Hi,

I have a use case with the following string:

http://tfs:8080/_ab/

It is not highlighting without a . in the hostname, but I think it should highlight if it detects the http:// protocol part

Make "localhost" into a URL

Hi,

It would be nice if the library interpreted "localhost" as a valid URL: http://localhost I am asking because we use localhost to test our web app, and it would be nice to have the links functional.

Is it possible to do it right now, with an option?

Merc.

It needs spaces before and after to work inside HTML

In my project, user writes text in a box, but behind the scenes,

tags are inserted (it applies to

and so on). I've noticed that anchorme doesn't do the job with this text. Here are some console tests which say everything:

anchorme.js('www.google.com')
"www.google.com"
anchorme.js('

www.google.com

') "

www.google.com

" anchorme.js('

www.google.com

') "

www.google.com

" anchorme.js('
google.com
') "
google.com
" anchorme.js('
google.com
') ""

Documentation JSFiddle demos are broken

After updating, the node distribution does not servers a one-file package thus I need to move edit JSFiddle snippets to have a rawgit link instead of unkpg.

Problem with excluding files

Hi,

We are facing issues with files converted to links. For example:
download.zip is getting converted to: <a href="http://download.zip" >download.zip</a>

We came across with property, files:false but it seems doesn't work:
jsFiddle

Please help.

Default console.log output

Default settings appear to output a console.log upon every parse. I have edited my local version but it would be nice if it didn't output these logs or if there was an option for them.

Object tag is not detected as html

Hi Alex,

I'm using emojis which are included with an <object> tag. For some reason anchorme does not detect this as html and does mistakenly process the url within the data attribute.

Lorem ipsum <object class="emoji" data="https://www.mydomain.com/svg/emoji/123.svg" type="image/svg+xml" standby=":)">:)</object>

I suppose it has something to do with data="https... because when I change it to src="https..., the <object> tag will be recognized and not break any more - but of course then the emoji will not show up.

Thanks in advance for any help :)

No more targets?

Is it no longer an option to assign a target attribute to the anchor? It no longer appears in the source or in the example options.

Update IANA list

Update IANA list. I might also setup an automated script that retrieves the list every week and updates the package automatically.

Cannot find module 'anchorme.js'

Hi,

How to use it with Node/npm? require('anchorme.js') always throws Error: Cannot find module 'anchorme.js'. I assume, this is because the name ends with .js.

Node version: v6.4.0

Percent-encoding breaks URLs

Some of the documents on our file server have spaces in their URL, e.g.

https://mydomain.com/My%20document.pdf

An URL with a percent sign is not recognized by anchorme.

e.g.

> anchorme.js("https://mydomain.com/My%20document.pdf");
< "https://mydomain.com/My%20document.pdf"

> anchorme.js("https://mydomain.com/My20document.pdf");
< "<a href='https://mydomain.com/My20document.pdf'>https://mydomain.com/My20document.pdf</a>"

Feature request: When truncating, put ellipsis in middle

Hi there,

Love the truncation option, but would it be possible even to have the ellipsis in the middle of the cut down URL (e.g. http://www.go...bla=blub&nice=1) instead of at the end, and maybe even drop the protocol from it too? All in order to make the shortened version even more useful and indicative of the actual link...

Cheers!

Ports with IP address

Wouldn't work on IP addresses with ports defined.

e.g:
127.0.0.1:3000

unless a protocol defined:
ftp://127.0.0.1:3000

Need to add _blank conditionally. Right now it is being added even for mailto://

Hi,

If we apply target= "_blank" in the attributes, we are getting target attribute added even for text converted to mailto:// .

for example:

anchorme("drop an email to [email protected]", {
                    attributes: {
                        "target": "_blank"
                    }
                }) 

Output:"drop an email to <a href='mailto:[email protected]' target='_blank' >mailto:[email protected]</a>"

Problem: It is unnecessarily opening a blank window on click.

Should there be someway, we can ignore the adding target attribute for email?

-Sumeet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.