diff --git a/lib/memex_web/components/core_components.ex b/lib/memex_web/components/core_components.ex index 9ab0b1e..dd725e0 100644 --- a/lib/memex_web/components/core_components.ex +++ b/lib/memex_web/components/core_components.ex @@ -121,67 +121,63 @@ defmodule MemexWeb.CoreComponents do attr :note, Note, required: true - def note_content(assigns) do - ~H""" -
<%= add_links_to_content(@note.content, "note-link") %>
<%= add_links_to_content(@context.content, "context-note") %>
<%= add_links_to_content(@step.content, "step-context") %>
" - end - ) - |> HTML.raw() + # link regex from + # https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url + # and modified with additional schemes from + # https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml + + content = + Regex.replace( + ~r<((file|git|https?|ipfs|ipns|irc|jabber|magnet|mailto|mumble|tel|udp|xmpp):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))>, + content, + fn _whole_match, link -> + link = + HTML.Link.link( + link, + to: link, + class: "link inline", + target: "_blank", + rel: "noopener noreferrer" + ) + |> HTML.Safe.to_iodata() + |> IO.iodata_to_binary() + + "
#{link}" + end + ) + + content = + 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: "#{data_qa_prefix}-#{slug}"] + ) + |> HTML.Safe.to_iodata() + |> IO.iodata_to_binary() + + "
#{link}" + end + ) + + content |> HTML.raw() end end diff --git a/lib/memex_web/components/core_components/context_content.html.heex b/lib/memex_web/components/core_components/context_content.html.heex new file mode 100644 index 0000000..4692f2e --- /dev/null +++ b/lib/memex_web/components/core_components/context_content.html.heex @@ -0,0 +1,8 @@ +
<%= add_links_to_content(@context.content, "context-note") %>
<%= add_links_to_content(@note.content, "note-link") %>
<%= add_links_to_content(@step.content, "step-context") %>