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/actions_dropdown.html.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex index fcd4589..cd40fb7 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex @@ -2,7 +2,7 @@ <:option> copied = true, () => copied = false ) diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex index 5ad0533..d5d43be 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex @@ -1,5 +1,5 @@ <%= if media_type(@media_item) == :video do %> -