Skip to content

Commit

Permalink
Automatically convert .livemd links
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 28, 2022
1 parent 363edfa commit 46df46e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ defmodule ExDoc.Formatter.HTML do

_ ->
raise ArgumentError,
"file extension not recognized, allowed extension is either .md, .txt or no extension"
"file extension not recognized, allowed extension is either .livemd, .md, .txt or no extension"
end

{title_ast, ast} =
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ defmodule ExDoc.Language.Elixir do
defp build_extra_link(link, config) do
with %{scheme: nil, host: nil, path: path} = uri <- URI.parse(link),
true <- is_binary(path) and path != "" and not (path =~ @ref_regex),
extension when extension in [".md", ".txt", ""] <- Path.extname(path) do
true <- Path.extname(path) in [".livemd", ".md", ".txt", ""] do
if file = config.extras[Path.basename(path)] do
fragment = (uri.fragment && "#" <> uri.fragment) || ""
file <> config.ext <> fragment
Expand Down
4 changes: 3 additions & 1 deletion test/ex_doc/language/elixir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ defmodule ExDoc.Language.ElixirTest do
end

test "extras" do
opts = [extras: %{"Foo Bar.md" => "foo-bar"}]
opts = [extras: %{"Foo Bar.md" => "foo-bar", "Bar Baz.livemd" => "bar-baz"}]

assert autolink_doc(~m"[Foo](Foo Bar.md)", opts) == ~m"[Foo](foo-bar.html)"

assert autolink_doc(~m"[Bar](Bar Baz.livemd)", opts) == ~m"[Bar](bar-baz.html)"

assert autolink_doc(~m"[Foo](Foo Bar.md)", [ext: ".xhtml"] ++ opts) ==
~m"[Foo](foo-bar.xhtml)"

Expand Down

0 comments on commit 46df46e

Please sign in to comment.