Search code examples
documentationjuliacross-reference

Cross-referencing functions from other submodule in Documenter.jl


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.


Solution

  • 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