0.01
No release in over a year
A Markdown view for Phlex
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.7
>= 0.5
 Project Readme

phlex-markdown

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

Community 🙌

Everyone interacting in Phlex codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Sponsorship 💖

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.

Security 🚨

If you’ve found a potential security issue, please email security@phlex.fun.