Skip to content

Instantly share code, notes, and snippets.

@joaohf
Last active November 2, 2020 20:38
Show Gist options
  • Save joaohf/a71f5682469ba6c8303b491087a3f057 to your computer and use it in GitHub Desktop.
Save joaohf/a71f5682469ba6c8303b491087a3f057 to your computer and use it in GitHub Desktop.
ex_docs with mermaid support
def project do
[
...
docs: docs(),
...
]
end
defp docs do
[
...
assets: mermaid_assets(),
before_closing_body_tag: mermaid_snippet(:file)
]
end
@doc """
Returns the relative or absolute path which has the mermaid.min.js file.
Fetch a copy of mermaid (from: https://mermaid-js.github.io/mermaid/)
and add it to the local _assets_ directory.
"""
def mermaid_assets() do
"assets"
end
@doc """
Returns a function that, when called, will return a html snippet with the correct file or
url to load mermaid.
"""
def mermaid_snippet(file_or_url) do
url = case file_or_url do
:file ->
"assets/mermaid.min.js"
url ->
url
end
fn (:html) ->
"""
<script src="#{url}"></script>
<script>mermaid.initialize({startOnLoad:true});</script>
"""
(_) -> ""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment