@inner_block is just a reference to a slot. If you want the contents then you need to render the slot with render_slot/2. Also while it may be fine with markdown I’m not sure you can have arbitrary text as slot content with heex.
Works like a charm (with phx-no-format)
Any idea how we could add a function component in the markdown, sth like:
<.markdown>
# Markdown with a function-component-call
This is some regular *markdown* content.
<.some_component foo="bar" />
And some more markdown.
</.markdown>
This obviously does not work with just render_slot().static.
this is what I came up with, no idea how evil it is. (handles only one inner block yet)
In the heex-template:
<div>
<Markdown.markdown phx-no-format>
# Markdown from inner-content
<%= "TEST" %>
*Hello* this is markdown from inner-content.
</Markdown.markdown>
</div>
the component:
def markdown(assigns) do
inner_block_rendered =
case assigns.inner_block do
[inner_block] ->
rendered =
inner_block.inner_block.(assigns.__changed__, nil)
|> Phoenix.HTML.Safe.to_iodata()
|> to_string()
_ ->
nil
end
dbg(inner_block_rendered)
...
end
rendered:
inner_block_rendered #=> "\n# Markdown from inner-content\nTEST\n*Hello* this is markdown from inner-content.\n "
I am using the MD Library to be able to render any HEEX template inside a markdown file, that is rendered by a custom Phoenix template engine and this is how I approached it:
I also like the idea of using the <.markdown> slot, need to try it out.