Coder Social home page Coder Social logo

java-autolinker's Introduction

An extendable autolinking library

Maven Central

Under the impression that it is nearly impossible to write a robust autolinker without parsing the input text to a dom tree, i’ve written an autolinker that uses Jsoup to build trees and proccess them in a way that new types of links can easily be added.

The core service of this project is the AutoLinkService which uses several AutoLinkers to add links to arbitrary text. 3 autolinkers (URLs, E-Mail adresses and Twitter Handles) are build in.

The project is a ready to use configured maven project and has nearly 100% test coverage.

Important

Since version 0.1.1 this project is Java 8 only.

Since version 0.2.1 this project is Java 10+ only. In addition, it uses Spring Boots dependency management.

Since version 0.3.1 I have changed the API of AutoLinkService and removed Optional<> as input parameter as suggested by various people (Joshua Bloch, Simon Harrer and others).

Usage

Standalone


public static void main(String... args) {
	// Instantiate AutoLinkService using all available autolinkers
	final AutoLinkService autoLinkService = new AutoLinkService(Arrays.asList(
		new EmailAddressAutoLinker(true, true),
		new TwitterUserAutoLinker(),
		new UrlAutoLinker(30)
	));
	// Autolink stuff
	System.out.println(autoLinkService.addLinks("Maybe there's a link http://michael-simons.eu to @rotnroll666", Optional.empty()));
}

or have a look at the test code.

The AutoLinkService can be easily registered as a

As a Spring bean


@Bean
public AutoLinkService autoLinkService(
  @Value("${dailyfratze.emailAddressAutoLinker.hexEncodeEmailAddress:true}") boolean hexEncodeEmailAddress,
  @Value("${dailyfratze.emailAddressAutoLinker.obfuscateEmailAddress:true}") boolean obfuscateEmailAddress,
  @Value("${dailyfratze.urlAutoLinker.maxLabelLength:30}") int maxLabelLength
) {
  return new AutoLinkService(Arrays.asList(
  		new EmailAddressAutoLinker(hexEncodeEmailAddress, obfuscateEmailAddress),
  		new TwitterUserAutoLinker(),
  		new UrlAutoLinker(maxLabelLength)
  ));
}

I assume you know what you’re doing with Spring, so i don’t explain that further.

Enjoy and if you find that library usefull, drop me a line or star it. Thanks.

java-autolinker's People

Contributors

michael-simons avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

java-autolinker's Issues

Test issue

Imma just put this here...

 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Entities.EscapeMode;
 import org.junit.Test;

 public class UF84bytes {
    @Test
    public void blah() {
        String s = "å  😄";
        Document d = Jsoup.parseBodyFragment(s);
        d.outputSettings().charset("UTF-8").escapeMode(EscapeMode.xhtml);
        System.out.println(d.html());
    }
 }

i expect this output

 <html>
  <head></head>
  <body>
   å 😄
  </body>
 </html>

but i get

 <html>
  <head></head>
  <body>
   å &#55357;&#56836;
  </body>
 </html>

And how about some without backticks?

å 😄

Reference project (not an issue)

Hi Michael, first of all thank you for sharing this project. I came across because we need to replace some autolinking we are doing on the frontend with Java code in the backend. And the FE team is using this for autolinking: https://github.com/gregjacobs/Autolinker.js.
Seems to be following a similar architecture, so I just wanted to share it with you.
I will be trying both projects.
Thanks again,
Leo

Still maintained / planned any release

I see its last commits before year. Is it still maintained ? Do you plan to release this project and and host artifacts any maven repositories.

Thanks,

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.