def workflow_link(workflow, rest=False, github_links=True):
    """Return a link for ``workflow`` in Markdown or ReST."""
    output = []

    if rest:
        output.append("`{name} <{url}>`__")

        if (
            github_links
            and workflow.get("github_repo_url")
            and workflow["github_repo_url"] != workflow["url"]
        ):
            output.append("(`GitHub repo <{github_repo_url}>`__)")

        if workflow.get("author_url"):
            if (
                github_links
                and workflow.get("github_user_url")
                and workflow["github_user_url"] != workflow["author_url"]
            ):
                output.append("by `{author} <{author_url}>`__")
                output.append("(`on GitHub <{github_user_url}>`__).")
            else:
                output.append("by `{author} <{author_url}>`__.")
        else:
            output.append("by {author}.")

        output.append("{description}")

        return "\n  ".join(output).format(**workflow)

    else:  # Markdown
        output.append("[{name}]({url})")

        if (
            github_links
            and workflow.get("github_repo_url")
            and workflow["github_repo_url"] != workflow["url"]
        ):
            output.append("([GitHub repo]({github_repo_url}))")

        if workflow.get("author_url"):
            if (
                github_links
                and workflow.get("github_user_url")
                and workflow["github_user_url"] != workflow["author_url"]
            ):
                output.append("by [{author}]({author_url})")
                output.append("([on GitHub]({github_user_url})).")
            else:
                output.append("by [{author}]({author_url}).")
        else:
            output.append(" by {author}.")

        output.append("\n  {description}")

        if rest:
            return "\n  ".join(output).format(**workflow)
        else:
            return " ".join(output).format(**workflow)