net.nemerosa.ontrack.model.support.LinkFreeTextAnnotatorContributor.kt Maven / Gradle / Ivy
package net.nemerosa.ontrack.model.support
import net.nemerosa.ontrack.model.structure.ProjectEntity
import org.springframework.stereotype.Component
import java.util.regex.Pattern
/**
* Provides an annotator which transforms any HTTP link
* into an actual link.
*/
@Component
class LinkFreeTextAnnotatorContributor : FreeTextAnnotatorContributor {
private val pattern = Pattern.compile("((https?://|ftp://|www\\.)\\S+)")
override fun getMessageAnnotators(entity: ProjectEntity): List =
listOf(
RegexMessageAnnotator(
pattern
) { link ->
MessageAnnotation.of("a")
.attr("href", link)
.attr("target", "_blank")
.text(link)
}
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy