backlink to other notes in notes
This commit is contained in:
44
lib/memex_web/components/note_content.ex
Normal file
44
lib/memex_web/components/note_content.ex
Normal file
@ -0,0 +1,44 @@
|
||||
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"""
|
||||
<div
|
||||
id={"show-note-content-#{@note.id}"}
|
||||
class="input input-primary h-128 min-h-128 inline-block"
|
||||
phx-hook="MaintainAttrs"
|
||||
phx-update="ignore"
|
||||
readonly
|
||||
phx-no-format
|
||||
><p class="inline"><%= add_links_to_content(@note.content) %></p></div>
|
||||
"""
|
||||
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()
|
||||
|
||||
"</p>#{link}<p class=\"inline\">"
|
||||
end
|
||||
)
|
||||
|> HTML.raw()
|
||||
end
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
defmodule MemexWeb.NoteLive.Show do
|
||||
use MemexWeb, :live_view
|
||||
|
||||
import MemexWeb.Components.NoteContent
|
||||
alias Memex.{Accounts.User, Notes, Notes.Note}
|
||||
|
||||
@impl true
|
||||
|
@ -5,14 +5,7 @@
|
||||
|
||||
<p><%= if @note.tags, do: @note.tags |> Enum.join(", ") %></p>
|
||||
|
||||
<textarea
|
||||
id="show-note-content"
|
||||
class="input input-primary h-128 min-h-128"
|
||||
phx-hook="MaintainAttrs"
|
||||
phx-update="ignore"
|
||||
readonly
|
||||
phx-no-format
|
||||
><%= @note.content %></textarea>
|
||||
<.note_content note={@note} />
|
||||
|
||||
<p class="self-end">
|
||||
<%= gettext("Visibility: %{visibility}", visibility: @note.visibility) %>
|
||||
|
Reference in New Issue
Block a user