Markdown Template Engine for Phoenix

A Markdown template engine for Phoenix. It also lets you (optionally) embed Liquid tags to be evaluated on the server.

Powered by Earmark and Solid

Based on phoenix_markdown

Usage

  1. Add {:phoenix_solid_markdown, "~> 0.1.0-rc.0"} to your deps in mix.exs.
  2. Add the following to your Phoenix config/config.exs
    config :phoenix, :template_solid_engines,
     md:     PhoenixSolidMarkdown.Engine,
     liquid: PhoenixSolidMarkdown.SolidEngine

If you are also using the phoenix_markdown engine, then it should look like this:

  config :phoenix, :template_engines,
    md:     PhoenixMarkdown.Engine,
    mds:    PhoenixSolidMarkdown.Engine,
    liquid: PhoenixSolidMarkdown.SolidEngine
  1. Use the .html.md or .html.mds or .html.liquid extensions for your templates.

Optional

Add md extension to Phoenix live reload in config/dev.exs

  config :hello_phoenix, HelloPhoenix.Endpoint,
    live_reload: [
      web_console_logger: true,
      patterns: [
        ~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
        ~r"priv/gettext/.*(po)$",
        ~r"lib/video_site_web/(?:controllers|live|components|router)/?.*\.(ex|heex|md|mds|liquid)$"
      ]
    ]

Optional Earmark Configuration

You can configure phoenix_solid_markdown via one configuration block, which will be passed to Earmark as it renders the markdown into html.

  config :phoenix_solid_markdown, :earmark, %{
    gfm: true,
    breaks: true
  }

Please read the Earmark Documentation to understand the options that can go here.

Unexpected Token in Server Tags

By default Earmark replaces some characters with prettier UTF-8 versions. For example, single and double quotes are replaced with left- and right-handed versions. This may break any server tag which contains a prettified character since EEx cannot interpret them as intended. To fix this, disable smartypants processing and escaping.

  config :phoenix_solid_markdown, :earmark, %{
    smartypants: false,
    escape: false
  }

Markdown is intended to be written by a human in any simple text editor ( or a fancy one like iA Writer ). Just create a file with the .html.md extension and drop it into the appropriate templates folder in your phoenix application. Then you can use it just like any other template.