def run(self): node_list = nodes.bullet_list() token = os.getenv('GITHUB_TOKEN') if token: g = Github(token) repo = g.get_repo(self.arguments[0]) folder = '' if not self.options['folder'] else self.options[ 'folder'] contents = repo.get_contents(folder, ref="gh-pages") for line in list(reversed(contents)): if '.md' in line.path: uri = 'https://github.com/' + self.arguments[ 0] + '/blob/gh-pages/' + line.path version = line.path.split('.md')[0] else: uri = self.docs_url + self.arguments[0].split( '/')[1] + '/' + line.path version = line.path.split('/')[-1] if not any(excluded_file_name in version for excluded_file_name in self.excluded_file_names): item = nodes.list_item() item_p = nodes.paragraph() item_p += nodes.reference(text=version, refuri=uri) item += item_p node_list += item return [node_list]
def run(self): node_list = nodes.bullet_list() token = os.getenv('GITHUB_ACCESS_TOKEN') if token: g = Github(token) repo = g.get_repo(self.arguments[0]) folder = '' if not self.options['folder'] else self.options['folder'] contents = repo.get_contents(folder, ref="gh-pages") clean_contents = [content for content in contents if not any(excluded_name in content.path for excluded_name in self.excluded_file_names)] sorted_contents = sorted(clean_contents, key=lambda x: LooseVersion(x.path.split('v')[-1]), reverse=True) count = 1 for line in sorted_contents: if '.md' in line.path: uri = 'https://github.com/' + self.arguments[0] + '/blob/gh-pages/' + line.path version = line.path.split('.md')[0] else: uri = self.docs_url + self.arguments[0].split('/')[1] + '/' + line.path version = line.path.split('/')[-1] if count == 1: version += ' (next)' if count == 2: version += ' (latest)' item = nodes.list_item() item_p = nodes.paragraph() item_p += nodes.reference(text=version, refuri=uri) item += item_p node_list += item count += 1 return [node_list]
def build_cite(rawtext, ref, lineno, inliner, options, template): if not ref in ads_data: msg = inliner.reporter.error('Reference {:s} not found'.format(ref), line=lineno) prb = inliner.problematic(rawtext, rawtext, msg) return [prb], [msg] year_str = re.findall(r'[0-9]+[A-Za-z]*', ref) if len(year_str) > 0: year = year_str[0] else: year = ads_data[ref].year if len(ads_data[ref].author) == 1: author = format(ads_data[ref].author[0].split(',')[0]) elif len(ads_data[ref].author) == 2: author = '{:s} & {:s}'.format(ads_data[ref].author[0].split(',')[0], ads_data[ref].author[1].split(',')[0]) else: author = '{:s} et al.'.format(ads_data[ref].author[0].split(',')[0]) citation = template.format(author, year) url = 'https://ui.adsabs.harvard.edu/abs/{:s}/abstract'.format( ads_data[ref].bibcode) node = nodes.reference(rawtext, citation, refuri=url, **options) return [node], []
def lsp_role(name, rawtext, text, lineno, inliner, options={}, content=[]): """Link to sections within the lsp specification.""" anchor = text.replace("/", "_") ref = f"https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#{anchor}" node = nodes.reference(rawtext, text, refuri=ref, **options) return [node], []
def github_role(name: str, rawtext: str, text: str, lineno: int, inliner: Inliner, options={}, content=[]): """格式化为链接 """ # 判断是仓库还是用户 title = f"Github - {text}" if "/" in text else f"{text}@GitHub" url = f"https://github.com/{text}" # 返回一个超链接结点 return [nodes.reference(rawsource=rawtext, text=title, refuri=url)], []
def file_role(role, rawtext, text, lineno, inliner, options={}, content={}): source = inliner.document.settings._source path = text name = util.basename(text) # name, link = _parse_ref(text) # file_dir = inliner.document.settings.file_directory file_dir = "files" source.deps += (Source(path, dir=file_dir, handler=FileHandler),) ref = file_dir + '/' + name #urljoin(file_dir, name) node = nodes.reference(rawtext, name, refuri=ref, **options) return [node], []
def reference_field(key, value, value_text=None): field_name = nodes.field_name(key, key) field_body_ref = nodes.reference(value, value_text or value, refuri=value) field_body_p = nodes.paragraph('', '', field_body_ref) field_body = nodes.field_body('', field_body_p) return nodes.field('', field_name, field_body)
format='html')) rv.append(nodes.image(data['title'] or '', uri=data['url'], alt=data['title'] or '', width=str(data['width']), height=str(data['height']))) rv.append(nodes.raw('', '</div>', format='html')) elif data['type'] == 'rich': rv.append(nodes.raw('', data['html'], format='html', classes=['oembed', 'oembed-rich'])) elif data['type'] == 'video': rv.append(nodes.raw('', data['html'], format='html', classes=['oembed', 'oembed-video'])) elif data['type'] == 'link': uri = directives.uri(self.arguments[0]) label = nodes.strong('Link: ', 'Link: ') link = nodes.reference(uri, data.get('title', uri), refuri=uri) rv.append(nodes.paragraph('', '', label, link)) return rv if 'hide-metadata' in self.options: return rv rvl = [] # always use title, if possible. if 'title' in data and data['title']: rvl.append(text_field('Title', data['title'])) # description isn't part of the spec. but should be used if provided. if 'description' in data: rvl.append(text_field('Description', data['description']))