Created
March 8, 2020 17:24
-
-
Save zookzook/7d41801ab7248a127742049c9169eca4 to your computer and use it in GitHub Desktop.
PageView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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