2021-09-12 21:03:59 +02:00
|
|
|
defmodule PhilomenaWeb.TextRenderer do
|
|
|
|
alias PhilomenaWeb.MarkdownRenderer
|
2021-09-14 23:41:46 +02:00
|
|
|
alias PhilomenaWeb.TextileMarkdownRenderer
|
2021-09-12 21:03:59 +02:00
|
|
|
|
|
|
|
def render_one(item, conn) do
|
|
|
|
hd(render_collection([item], conn))
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_collection(items, conn) do
|
|
|
|
Enum.map(items, fn item ->
|
|
|
|
if Map.has_key?(item, :body_md) && item.body_md != nil && item.body_md != "" do
|
|
|
|
MarkdownRenderer.render(item.body_md, conn)
|
|
|
|
else
|
2021-09-14 23:41:46 +02:00
|
|
|
markdown = TextileMarkdownRenderer.render_one(item)
|
|
|
|
MarkdownRenderer.render(markdown, conn)
|
2021-09-12 21:03:59 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|