philomena/lib/philomena_web/textile_markdown_renderer.ex

23 lines
474 B
Elixir
Raw Normal View History

2021-09-12 18:59:44 +02:00
defmodule PhilomenaWeb.TextileMarkdownRenderer do
alias Philomena.Textile.ParserMarkdown
2021-09-14 01:08:47 +02:00
def render_one(post) do
hd(render_collection([post]))
2021-09-12 18:59:44 +02:00
end
2021-09-14 01:08:47 +02:00
def render_collection(posts) do
2021-09-12 18:59:44 +02:00
opts = %{image_transform: &Camo.Image.image_url/1}
parsed = Enum.map(posts, &ParserMarkdown.parse(opts, &1.body))
parsed
|> Enum.map(fn tree ->
tree
|> Enum.map(fn
{_k, text} ->
text
end)
|> Enum.join()
end)
end
end