Function to get docs of a package to open in a browser window?

I define this macro. It’s useful sometimes:

readreadme(mod::Module) = readreadme(Base.PkgId(mod))

function readreadme(pkg::Base.PkgId)
    path = joinpath(dirname(dirname(Base.locate_package(pkg))), "README.md")
    return Markdown.parse_file(path)
end

"""
    @readreadme module

Read README.md of `module`.
"""
macro readreadme(ex)
    quote
        mod = try
            $(esc(ex))
        catch err
            err isa UndefVarError || rethrow()
            nothing
        end
        if mod === nothing
            readreadme(Base.identify_package($(string(ex))))
        else
            readreadme(mod)
        end
    end
end
4 Likes