embed links
This commit is contained in:
parent
50b7f8f9b6
commit
7d16cec5db
@ -121,50 +121,45 @@ defmodule MemexWeb.CoreComponents do
|
|||||||
|
|
||||||
attr :note, Note, required: true
|
attr :note, Note, required: true
|
||||||
|
|
||||||
def note_content(assigns) do
|
def note_content(assigns)
|
||||||
~H"""
|
|
||||||
<div
|
|
||||||
id={"show-note-content-#{@note.id}"}
|
|
||||||
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
|
||||||
phx-hook="MaintainAttrs"
|
|
||||||
phx-update="ignore"
|
|
||||||
readonly
|
|
||||||
phx-no-format
|
|
||||||
><p class="inline"><%= add_links_to_content(@note.content, "note-link") %></p></div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
attr :context, Context, required: true
|
attr :context, Context, required: true
|
||||||
|
|
||||||
def context_content(assigns) do
|
def context_content(assigns)
|
||||||
~H"""
|
|
||||||
<div
|
|
||||||
id={"show-context-content-#{@context.id}"}
|
|
||||||
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
|
||||||
phx-hook="MaintainAttrs"
|
|
||||||
phx-update="ignore"
|
|
||||||
readonly
|
|
||||||
phx-no-format
|
|
||||||
><p class="inline"><%= add_links_to_content(@context.content, "context-note") %></p></div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
attr :step, Step, required: true
|
attr :step, Step, required: true
|
||||||
|
|
||||||
def step_content(assigns) do
|
def step_content(assigns)
|
||||||
~H"""
|
|
||||||
<div
|
|
||||||
id={"show-step-content-#{@step.id}"}
|
|
||||||
class="input input-primary h-32 min-h-32 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
|
||||||
phx-hook="MaintainAttrs"
|
|
||||||
phx-update="ignore"
|
|
||||||
readonly
|
|
||||||
phx-no-format
|
|
||||||
><p class="inline"><%= add_links_to_content(@step.content, "step-context") %></p></div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
defp add_links_to_content(content, data_qa_prefix) do
|
defp add_links_to_content(content, data_qa_prefix) do
|
||||||
|
# replace links
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
"</p>#{link}<p class=\"inline\">"
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
content =
|
||||||
Regex.replace(
|
Regex.replace(
|
||||||
~r/\[\[([\p{L}\p{N}\-]+)\]\]/,
|
~r/\[\[([\p{L}\p{N}\-]+)\]\]/,
|
||||||
content,
|
content,
|
||||||
@ -182,6 +177,7 @@ defmodule MemexWeb.CoreComponents do
|
|||||||
"</p>#{link}<p class=\"inline\">"
|
"</p>#{link}<p class=\"inline\">"
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|> HTML.raw()
|
|
||||||
|
content |> HTML.raw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
id={"show-context-content-#{@context.id}"}
|
||||||
|
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
||||||
|
phx-hook="MaintainAttrs"
|
||||||
|
phx-update="ignore"
|
||||||
|
readonly
|
||||||
|
phx-no-format
|
||||||
|
><p class="inline"><%= add_links_to_content(@context.content, "context-note") %></p></div>
|
@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
id={"show-note-content-#{@note.id}"}
|
||||||
|
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
||||||
|
phx-hook="MaintainAttrs"
|
||||||
|
phx-update="ignore"
|
||||||
|
readonly
|
||||||
|
phx-no-format
|
||||||
|
><p class="inline"><%= add_links_to_content(@note.content, "note-link") %></p></div>
|
@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
id={"show-step-content-#{@step.id}"}
|
||||||
|
class="input input-primary h-32 min-h-32 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
|
||||||
|
phx-hook="MaintainAttrs"
|
||||||
|
phx-update="ignore"
|
||||||
|
readonly
|
||||||
|
phx-no-format
|
||||||
|
><p class="inline"><%= add_links_to_content(@step.content, "step-context") %></p></div>
|
Loading…
Reference in New Issue
Block a user