Skip to content

Commit feeddc1

Browse files
authored
Add support for path dependent markdown autolink (#1187)
1 parent 695012e commit feeddc1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/ex_doc/autolink.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ defmodule ExDoc.Autolink do
105105
uri <- URI.parse(href),
106106
nil <- uri.host,
107107
true <- is_binary(uri.path),
108-
true <- uri.path == Path.basename(uri.path),
109108
".md" <- Path.extname(uri.path) do
110-
if uri.path in config.extras do
111-
without_ext = String.trim_trailing(uri.path, ".md")
109+
md_file = Path.basename(uri.path)
110+
111+
if md_file in config.extras do
112+
without_ext = String.trim_trailing(md_file, ".md")
112113
fragment = (uri.fragment && "#" <> uri.fragment) || ""
113114
HTML.text_to_id(without_ext) <> config.ext <> fragment
114115
else

test/ex_doc/autolink_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ defmodule ExDoc.AutolinkTest do
202202

203203
assert autolink(~m"[Foo](Foo Bar.md#baz)", opts) == ~m"[Foo](foo-bar.html#baz)"
204204

205+
assert autolink(~m"[Foo](../guide/Foo Bar.md)", opts) == ~m"[Foo](foo-bar.html)"
206+
205207
assert_unchanged(~m"[Foo](http://example.com/foo.md)", opts)
206208

207209
assert_unchanged(~m"[Foo](#baz)", opts)

0 commit comments

Comments
 (0)