From 25b4f9961308ec69852f1fd4aaac2907245fda20 Mon Sep 17 00:00:00 2001 From: calvin s Date: Fri, 12 Jun 2020 04:17:14 +0700 Subject: [PATCH 1/2] add support for path dependent markdown autolink --- lib/ex_doc/autolink.ex | 6 +++--- test/ex_doc/autolink_test.exs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ex_doc/autolink.ex b/lib/ex_doc/autolink.ex index 28b5c6ffb..dd3bb99cb 100644 --- a/lib/ex_doc/autolink.ex +++ b/lib/ex_doc/autolink.ex @@ -105,10 +105,10 @@ defmodule ExDoc.Autolink do uri <- URI.parse(href), nil <- uri.host, true <- is_binary(uri.path), - true <- uri.path == Path.basename(uri.path), ".md" <- Path.extname(uri.path) do - if uri.path in config.extras do - without_ext = String.trim_trailing(uri.path, ".md") + md_file = Path.basename(uri.path) + if md_file in config.extras do + without_ext = String.trim_trailing(md_file, ".md") fragment = (uri.fragment && "#" <> uri.fragment) || "" HTML.text_to_id(without_ext) <> config.ext <> fragment else diff --git a/test/ex_doc/autolink_test.exs b/test/ex_doc/autolink_test.exs index e621c152c..2e96e772f 100644 --- a/test/ex_doc/autolink_test.exs +++ b/test/ex_doc/autolink_test.exs @@ -202,6 +202,8 @@ defmodule ExDoc.AutolinkTest do assert autolink(~m"[Foo](Foo Bar.md#baz)", opts) == ~m"[Foo](foo-bar.html#baz)" + assert autolink(~m"[Foo](../guide/Foo Bar.md)", opts) == ~m"[Foo](foo-bar.html)" + assert_unchanged(~m"[Foo](http://example.com/foo.md)", opts) assert_unchanged(~m"[Foo](#baz)", opts) From 4c95a3a98959c7bde6836a4595b31715c7fe58b0 Mon Sep 17 00:00:00 2001 From: calvin s Date: Fri, 12 Jun 2020 04:27:06 +0700 Subject: [PATCH 2/2] mix format --- lib/ex_doc/autolink.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ex_doc/autolink.ex b/lib/ex_doc/autolink.ex index dd3bb99cb..927c62699 100644 --- a/lib/ex_doc/autolink.ex +++ b/lib/ex_doc/autolink.ex @@ -107,6 +107,7 @@ defmodule ExDoc.Autolink do true <- is_binary(uri.path), ".md" <- Path.extname(uri.path) do md_file = Path.basename(uri.path) + if md_file in config.extras do without_ext = String.trim_trailing(md_file, ".md") fragment = (uri.fragment && "#" <> uri.fragment) || ""