Packages
pow_assent
0.4.2
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0
0.1.0-rc.2
0.1.0-rc.1
0.1.0-rc.0
0.1.0-alpha.12
0.1.0-alpha.11
0.1.0-alpha.10
0.1.0-alpha.9
0.1.0-alpha.8
0.1.0-alpha.7
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
retired
0.1.0-alpha.1
0.1.0-alpha
Multi-provider support for Pow
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/ex_doc/markdown.ex
if Code.ensure_loaded?(ExDoc.Markdown.Earmark) do
# Due to how relative links works in ExDoc, it's necessary for us to use a
# custom markdown parser to ensure that paths will work in generated docs.
#
# Ref: https://github.com/elixir-lang/ex_doc/issues/889
defmodule ExDoc.PowAssent.Markdown do
@moduledoc false
alias ExDoc.Markdown.Earmark
@behaviour ExDoc.Markdown
defdelegate assets(arg), to: Earmark
defdelegate before_closing_head_tag(arg), to: Earmark
defdelegate before_closing_body_tag(arg), to: Earmark
defdelegate configure(arg), to: Earmark
defdelegate available?(), to: Earmark
def to_html(text, opts) do
config = Mix.Project.config()[:docs]
source_url = config[:source_url] <> "/" <> source_ref_pattern(config[:source_url], config[:source_ref])
text
|> convert_relative_docs_url(source_url)
|> Earmark.to_html(opts)
end
defp source_ref_pattern("https://github.com/" <> _rest, ref), do: "blob/#{ref}"
@markdown_regex ~r/(\[[\S ]*\]\()([\S]*?)(\.md|\.ex|\.exs)([\S]*?\))/
defp convert_relative_docs_url(text, source_url) do
Regex.replace(@markdown_regex, text, fn
_, arg1, "http" <> path, extension, arg3 -> "#{arg1}http#{path}#{extension}#{arg3}"
_, arg1, path, ".md", arg3 -> "#{arg1}#{convert_to_docs_html_url(path)}.html#{arg3}"
_, arg1, path, extension, arg3 when extension in [".ex", ".exs"] -> "#{arg1}#{convert_to_source_url(path, extension, source_url)}#{arg3}"
end)
end
defp convert_to_docs_html_url("../README"), do: "README"
defp convert_to_docs_html_url("guides/" <> guide), do: guide
defp convert_to_docs_html_url(path), do: path
defp convert_to_source_url("lib/" <> path, extension, source_url), do: source_url <> "/lib/" <> path <> extension
end
end