2022-11-26 21:26:21 -05:00
|
|
|
defmodule MemexWeb.Components.StepContent do
|
|
|
|
@moduledoc """
|
|
|
|
Display the content for a step
|
|
|
|
"""
|
|
|
|
use MemexWeb, :component
|
|
|
|
alias Memex.Pipelines.Steps.Step
|
|
|
|
alias Phoenix.HTML
|
|
|
|
|
|
|
|
attr :step, Step, required: true
|
|
|
|
|
|
|
|
def step_content(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div
|
|
|
|
id={"show-step-content-#{@step.id}"}
|
2022-12-19 23:16:12 -05:00
|
|
|
class="input input-primary h-32 min-h-32 inline-block overflow-x-hidden overflow-y-auto"
|
2022-11-26 21:26:21 -05:00
|
|
|
phx-hook="MaintainAttrs"
|
|
|
|
phx-update="ignore"
|
|
|
|
readonly
|
|
|
|
phx-no-format
|
|
|
|
><p class="inline"><%= add_links_to_content(@step.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.context_show_path(Endpoint, :show, slug),
|
|
|
|
class: "link inline",
|
|
|
|
data: [qa: "step-context-#{slug}"]
|
|
|
|
)
|
|
|
|
|> HTML.Safe.to_iodata()
|
|
|
|
|> IO.iodata_to_binary()
|
|
|
|
|
|
|
|
"</p>#{link}<p class=\"inline\">"
|
|
|
|
end
|
|
|
|
)
|
2022-12-19 21:09:57 -05:00
|
|
|
|> String.replace("\n", "<br>")
|
2022-11-26 21:26:21 -05:00
|
|
|
|> HTML.raw()
|
|
|
|
end
|
|
|
|
end
|