-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ | |
*.rabit | ||
*.mock | ||
dmlc-core | ||
recommonmark | ||
recommonmark | ||
recom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Helper utilty function for customization.""" | ||
import sys | ||
import os | ||
import subprocess | ||
|
||
if os.environ.get('READTHEDOCS', None) == 'True': | ||
subprocess.call('cd ..; git clone https://github.com/tqchen/recommonmark recommonmark-customized;' + | ||
'ln -s recommonmark-customized/recommonmark recom', shell=True) | ||
|
||
sys.path.insert(0, os.path.abspath('..')) | ||
from recom import parser | ||
|
||
class MarkdownParser(parser.CommonMarkParser): | ||
github_doc_root = None | ||
|
||
@staticmethod | ||
def remap_url(url): | ||
if MarkdownParser.github_doc_root is None or url is None: | ||
return url | ||
arr = url.split('#', 1) | ||
if arr[0].endswith('.md') and arr[0].find('://') == -1: | ||
arr[0] = arr[0][:-3] + '.html' | ||
return '#'.join(arr) | ||
else: | ||
return MarkdownParser.github_doc_root + url | ||
|
||
def reference(self, block): | ||
block.destination = remap_url(block.destination) | ||
return super(MarkdownParser, self).reference(block) | ||
|
||
# inplace modify the function in recommonmark module to allow link remap | ||
old_ref = parser.reference | ||
|
||
def reference(block): | ||
block.destination = MarkdownParser.remap_url(block.destination) | ||
return old_ref(block) | ||
|
||
parser.reference = reference |