11

Given a module hierarchy like

module A
    module B; function foo end; end
    module C
        """
            bar(x)

        Like [`foo`](@ref), but more `bar`.
        """
        function bar end
    end
end

How could I cross-reference foo from the docstring of bar using Documenter.jl? I have tried A.B.foo, B.foo, and ..B.foo without success.

fredrikekre
  • 10,413
  • 1
  • 32
  • 47
Fengyang Wang
  • 11,901
  • 2
  • 38
  • 67
  • What do you mean by "cross-reference"? Are you saying one would be able to do `?A.C.bar` and then click on the highlighted `foo` in help mode and trigger `?A.B.foo` ? I haven't seen that with other functions, I've only seen highlighting (as you've done). – Tasos Papastylianou Feb 22 '17 at 10:12
  • 3
    @TasosPapastylianou While the Julia REPL does not have that feature, [Documenter does](https://juliadocs.github.io/Documenter.jl/stable/man/syntax.html#@ref-link-1). – Fengyang Wang Feb 22 '17 at 16:59
  • Ah, I do apologise, I must have missed it in the title earlier! (also I was not aware of Documenter.jl) :) – Tasos Papastylianou Feb 22 '17 at 20:33
  • @FengyangWang did you get this figured out? I'm in a similar situation now, getting doc reference errors and not sure what to do to fix it. – Sundar R May 17 '18 at 11:49

1 Answers1

10

First, both B.foo and C.bar needs to (i) have docstrings and (ii) be in the markdown file, e.g. in a Documenter @docs block.

```@docs
A.B.foo
A.C.bar
```

in order to cross-reference between them. Second, the binding B.foo must be visible inside the C module. This can be achieved by, for example, adding import ..B: foo in the C module (or adding export foo in B and using ..B in C). Here is a working example:

module A
    module B
        "foo function"
        function foo end
    end
    module C
        import ..B: foo
        """
            bar(x)

        Like [`foo`](@ref), but more `bar`.
        """
        function bar end
    end
end # module
fredrikekre
  • 10,413
  • 1
  • 32
  • 47