Skip to content

Instantly share code, notes, and snippets.

@zookzook
Created March 8, 2020 17:24
Show Gist options
  • Select an option

  • Save zookzook/7d41801ab7248a127742049c9169eca4 to your computer and use it in GitHub Desktop.

Select an option

Save zookzook/7d41801ab7248a127742049c9169eca4 to your computer and use it in GitHub Desktop.
PageView
defmodule PolarisWeb.PageView do
use PolarisWeb, :view
def markdown(string) do
with {:ok, html_doc, []} <- Earmark.as_html(strip_margin(string)) do
html_doc
end
end
def strip_margin(string) do
String.split(string, "\n")
|> Enum.map(fn line -> strip_margin_line(line) end)
|> Enum.join("\n")
end
def strip_margin_line(<<"|", rest::bits>>) do
rest
end
def strip_margin_line(<<" ", rest::bits>>) do
strip_margin_line(rest)
end
def strip_margin_line(string) do
string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment