Phlex::Markdown
is a Phlex view that renders Markdown into HTML using Phlex. You could use it directly — it takes a String of markdown and renders it to safe HTML.
Alternatively, you can define a sub-class and override various methods to customise the output.
For example, here we override h1
and ul
, adding some Tailwind classes to them.
class MyMarkdown < Phlex::Markdown
def h1 = super(class: "font-bold text-xl")
def ul = super(class: "ml-4 pt-2")
end
When we render the view.
content = <<~MD
# Hello World
- A
- B
- C
MD
output = MyMarkdown.new(content).call
The output
will use the attributes from our methods.
<h1 class="font-bold text-xl">Hello World</h1>
<ul class="ml-4 pt-2">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
You could also wrap the whole document in an <article>
element by overriding template
.
class MyMarkdownArticle < Phlex::Markdown
def template
article(class: "prose") { super }
end
end
Everyone interacting in Phlex codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Maintaining a library is a lot of work. If your company benefits from this work or is likely to benefit from it in the future, please consider sponsorship. Phlex is actively developed and maintained by Joel Drapper.
If you’ve found a potential security issue, please email security@phlex.fun.