Resolve Link¶
The viewsource_resolve_link
function set in config.py
is editable to fit your documentation needs.
-
viewsource_resolve_link
(file_path, language=None)¶ Defines the link resolution strategy for each code of block.
Parameters: - file_path (string) – Contains the path of the file included.
- language (string) – Contains the name of the highlighting language if set.
Returns: URL pointing to the file as string
Here there are some popular configurations that you can use to set up the link resolution strategy.
Point to an internal file¶
viewsource_title = 'Get the Code'
def viewsource_resolve_link(file_path, language=None):
snippets_folder = '/snippets/'
# get the name of the file
path_split = file_path.split('/')
file = path_split[len(path_split)-1]
return snippets_folder + file
Point to an external file¶
viewsource_title = 'Edit on Github'
def viewsource_resolve_link(file_path, language=None):
base_url = 'https://github.com/dgarcia360/sphinxcontrib-viewsource/blob/master/docs/snippets/'
# get the name of the file
path_split = file_path.split('/')
file = path_split[len(path_split)-1]
return base_url + file
Resolution strategy per language¶
viewsource_title = 'Edit on Github'
def viewsource_resolve_link(file_path, language=None):
# get the name of the file
path_split = file_path.split('/')
file = path_split[len(path_split)-1]
url = 'https://github.com/dgarcia360/sphinxcontrib-viewsource/blob/master/docs/python/%s' % file
if language == 'java':
return 'https://github.com/dgarcia360/sphinxcontrib-viewsource/blob/master/docs/java/src/%s' % file
return url