defmodule MemexWeb.Components.ContextContent do @moduledoc """ Display the content for a context """ use MemexWeb, :component alias Memex.Contexts.Context alias Phoenix.HTML attr :context, Context, required: true def context_content(assigns) do ~H"""

<%= add_links_to_content(@context.content) %>

""" end defp add_links_to_content(content) do Regex.replace( ~r/\[\[([\p{L}\p{N}\-]+)\]\]/, content, fn _whole_match, slug -> link = HTML.Link.link( "[[#{slug}]]", to: Routes.note_show_path(Endpoint, :show, slug), class: "link inline", data: [qa: "context-note-#{slug}"] ) |> HTML.Safe.to_iodata() |> IO.iodata_to_binary() "

#{link}

" end ) |> String.replace("\n", "
") |> HTML.raw() end end