net.nemerosa.ontrack.model.support.LinkFreeTextAnnotatorContributor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-model Show documentation
Show all versions of ontrack-model Show documentation
Ontrack module: ontrack-model
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