mirror of
https://github.com/ClaperCo/Claper.git
synced 2025-12-17 04:17:59 +01:00
18 lines
422 B
Elixir
18 lines
422 B
Elixir
|
|
defmodule ClaperWeb.Helpers do
|
||
|
|
def format_body(body) do
|
||
|
|
url_regex = ~r/(https?:\/\/[^\s]+)/
|
||
|
|
|
||
|
|
body
|
||
|
|
|> String.split(url_regex, include_captures: true)
|
||
|
|
|> Enum.map(fn
|
||
|
|
"http" <> _rest = url ->
|
||
|
|
Phoenix.HTML.raw(
|
||
|
|
~s(<a href="#{url}" target="_blank" class="cursor-pointer text-primary-500 hover:underline font-medium">#{url}</a>)
|
||
|
|
)
|
||
|
|
|
||
|
|
text ->
|
||
|
|
text
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
end
|