Document refactor

change badge
This commit is contained in:
tqchen
2015-08-01 13:47:41 -07:00
parent c43fee541d
commit e8de5da3a5
20 changed files with 286 additions and 184 deletions

View File

@@ -1,50 +1,17 @@
# -*- coding: utf-8 -*-
"""Helper hacking utilty function for customization."""
"""Helper utilty function for customization."""
import sys
import os
import docutils
import subprocess
# TODO: make less hacky way than this one
if os.environ.get('READTHEDOCS', None) == 'True':
subprocess.call('cd ..; rm -rf recommonmark;' +
subprocess.call('cd ..; rm -rf recommonmark recom;' +
'git clone https://github.com/tqchen/recommonmark;' +
'cp recommonmark/recommonmark/parser.py doc/parser', shell=True)
'mv recommonmark/recommonmark recom', shell=True)
sys.path.insert(0, os.path.abspath('..'))
import parser
from recom import parser, transform
class MarkdownParser(parser.CommonMarkParser):
github_doc_root = None
doc_suffix = set(['md', 'rst'])
@staticmethod
def remap_url(url):
if MarkdownParser.github_doc_root is None or url is None:
return url
if url.startswith('#'):
return url
arr = url.split('#', 1)
ssuffix = arr[0].rsplit('.', 1)
if len(ssuffix) == 2 and (ssuffix[-1] in MarkdownParser.doc_suffix
and arr[0].find('://') == -1):
arr[0] = ssuffix[0] + '.html'
return '#'.join(arr)
else:
if arr[0].find('://') == -1:
return MarkdownParser.github_doc_root + url
else:
return 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
MarkdownParser = parser.CommonMarkParser
AutoStructify = transform.AutoStructify