defmodule MemexWeb.Components.NoteContent do @moduledoc """ Display the content for a note """ use MemexWeb, :component alias Memex.Notes.Note alias Phoenix.HTML attr :note, Note, required: true def note_content(assigns) do ~H"""

<%= add_links_to_content(@note.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: "note-link-#{slug}"] ) |> HTML.Safe.to_iodata() |> IO.iodata_to_binary() "

#{link}

" end ) |> HTML.raw() end end