diff --git a/lib/pinchflat_web/components/custom_components/text_components.ex b/lib/pinchflat_web/components/custom_components/text_components.ex index e5cc4eb..9319c55 100644 --- a/lib/pinchflat_web/components/custom_components/text_components.ex +++ b/lib/pinchflat_web/components/custom_components/text_components.ex @@ -62,17 +62,24 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do end @doc """ - Renders a block of text with each line broken into a separate span. + Renders a block of text with each line broken into a separate span and links highlighted. """ attr :text, :string, required: true - def break_on_newline(assigns) do - broken_text = - assigns.text - |> String.split("\n", trim: false) - |> Enum.intersperse(Phoenix.HTML.Tag.tag(:span, class: "inline-block mt-2")) + def render_description(assigns) do + formatted_text = + Regex.split(~r{https?://\S+}, assigns.text, include_captures: true) + |> Enum.map(fn + "http" <> _ = url -> + Phoenix.HTML.Tag.content_tag(:a, url, class: "text-blue-500 hover:text-blue-300", href: url, target: "_blank") - assigns = Map.put(assigns, :text, broken_text) + text -> + text + |> String.split("\n", trim: false) + |> Enum.intersperse(Phoenix.HTML.Tag.tag(:span, class: "inline-block mt-2")) + end) + + assigns = Map.put(assigns, :text, formatted_text) ~H""" <%= @text %> diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex index 9e00c03..5d16070 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex @@ -45,7 +45,7 @@