261023.3 · 2748f9bb997af01b8c7e62bce2571bc4da28614e
Wiki links
A doc renders [[name]] as a link to name.md in its own directory, and [[sub/name]] to sub/name.md, as a relative link resolves. A name with an extension keeps it. [[name|label]] shows the label and [[name#heading]] opens at the heading, by the id goldmark gives it.
The parser runs before goldmark's link parser and leaves anything that is not a wiki link to it, so [[x]](y) stays a link with the text [x]. Its links are plain links in the tree, so a missing target is marked broken and backlinks count them.
reading declarations
Changes to backlinks_test.go. All files
@@ -23,6 +23,7 @@ func TestBacklinks(t *testing.T) { write("d/e.md", "[ref][r]\n\n[r]: ../index.md\n") write("d/f.md", "[elsewhere](../a/b.go) and index.md in prose\n") write(".git/g.md", "[hidden](../index.md)\n")+ write("w.md", "[[index]]\n") links := func(name string) []string { t.Helper() w := get(s.handler(), name+"?backlinks")@@ -50,7 +51,7 @@ func TestBacklinks(t *testing.T) { } } }- eq(links("/index.md"), "/a/c.md", "/d/e.md")+ eq(links("/index.md"), "/a/c.md", "/d/e.md", "/w.md") eq(links("/a/b.go"), "/d/f.md", "/index.md") eq(links("/a/c.md")) @@ -59,5 +60,5 @@ func TestBacklinks(t *testing.T) { os.Chtimes(filepath.Join(dir, "d/e.md"), time.Now(), time.Now().Add(time.Second)) os.Remove(filepath.Join(dir, "a/c.md")) write("h.md", "[i](index.md)\n")- eq(links("/index.md"), "/h.md")+ eq(links("/index.md"), "/h.md", "/w.md") }