Giter VIP home page Giter VIP logo

sphinxcontrib-markdown-symlinks's Introduction

Sphinx Contrib - Markdown Symlinks

This small Python file enables you to create a symbolic link to markdown pages outside your docs directory and have links still work. This is useful if you have things like the CONTRIBUTING.md or CODE_OF_CONDUCT.md in your repository that you also want to appear in your Sphinx documentation.

As the Markdown documents will have links relative to the source code root, rather than the place they are now linked too, this code will fixes these paths up.

The code also makes relative links between two Markdown documents found inside the Sphinx documentation work even if there relative positions are now totally different.

Install

You can install it either via;

pip install -e "git+https://github.com/SymbiFlow/sphinxcontrib-markdown-symlinks"

Or add the following to your requirements.txt

-e git+https://github.com/SymbiFlow/sphinxcontrib-markdown-symlinks

Set Up

# Add Markdown support by following the recommonmark install instructions.
# https://recommonmark.readthedocs.io/en/latest/#getting-started

from markdown_code_symlinks import LinkParser, MarkdownSymlinksDomain

source_parsers = {
    '.md': 'markdown_code_symlinks.LinkParser',
}

source_suffix = ['.rst', '.md']

def setup(app):
    github_code_repo = 'https://github.com/repo/link'
    github_code_branch = 'blob/your/branch'

    docs_root_dir = os.path.realpath(os.path.dirname(__file__))
    # Create code root dir relative to docs_root_dir
    code_root_dir = os.path.realpath(os.path.join(docs_root_dir, "..", ".."))

    MarkdownSymlinksDomain.init_domain(
        github_code_repo, github_code_branch, docs_root_dir, code_root_dir)
    MarkdownSymlinksDomain.find_links()
    app.add_domain(MarkdownSymlinksDomain)
    app.add_config_value(
        'recommonmark_config', {
            'github_code_repo': github_code_repo,
        }, True)

When running, the build should output something like the following now;

{'code2docs': {'BUILDING.md': 'sth/build_sth.md',
               'CONTRIBUTING.md': 'sth/dev/guidelines.md',
               'README.developers.md': 'sth/dev/index.md'},
 'docs2code': {'sth/build_sth.md': 'BUILDING.md',
               'sth/dev/guidelines.md': 'CONTRIBUTING.md',
               'sth/dev/index.md': 'README.developers.md'}}

License

This extension is available under your choice of;

sphinxcontrib-markdown-symlinks's People

Contributors

acomodi avatar rw1nkler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.