def run_convert_to_html(): for md_file_path, save_file_path in get_open_save_file_paths(): with open(md_file_path, 'r') as f: html = render_page(f.read(), os.path.split(md_file_path)[1]) html = html.replace('<pre><code>', '<pre>') html = html.replace('</code></pre>', '</pre>') html = html[html.find('<body>') + len('<body>'):] # chop off the generated header html = html[:html.rfind('</body>')] # chop off </body></html> head = header if 'func_groups' in save_file_path: head = head.replace('"index.html"', '"../index.html"') head = head.replace('"doc_index.html"', '"../doc_index.html"') head = head.replace('"stylesheets/', '"../stylesheets/') lines = html.split('\n') for i, line in enumerate(lines): if 'FLOAT_RIGHT' in line: line = line.replace('FLOAT_RIGHT', '') lines[i] = line.replace('<a ', '<a class="float-right" ') html = ''.join([head, '\n'.join(lines), footer]) with open(save_file_path, 'w') as f: f.write(html)
def run_convert_to_html(): for md_file_path, save_file_path in get_open_save_file_paths(): with open(md_file_path, 'r') as f: html = render_page(f.read(), os.path.split(md_file_path)[1]) html = html.replace('<pre><code>', '<pre>') html = html.replace('</code></pre>', '</pre>') html = html[html.find('<body>')+len('<body>'):] # chop off the generated header html = html[:html.rfind('</body>')] # chop off </body></html> head = header if 'func_groups' in save_file_path: head = head.replace('"index.html"', '"../index.html"') head = head.replace('"doc_index.html"', '"../doc_index.html"') head = head.replace('"stylesheets/', '"../stylesheets/') lines = html.split('\n') for i, line in enumerate(lines): if 'FLOAT_RIGHT' in line: line = line.replace('FLOAT_RIGHT', '') lines[i] = line.replace('<a ', '<a class="float-right" ') html = ''.join([head, '\n'.join(lines), footer]) with open(save_file_path, 'w') as f: f.write(html)
def build_or_cache(): """ get html which built or cached """ if should_build(): if not self.grip_option["username"] and self.login: login_info = self.login() self.grip_option.update(login_info) rendered_page = render_page(path, **self.grip_option) soup = BeautifulSoup(rendered_page, "lxml") if soup.article is None: raise Exception(soup.h1.get_text()) if self.option["embed_img"]: for img in soup.find_all("img"): img_src = unquote(img["src"]) __img = embed_image(path_dir, img_src) img["src"] = __img["src"] img["alt"] = __img["alt"] if not exists(dirname(cache_path)): makedirs(dirname(cache_path)) with open(cache_path, "w") as cache_file: cache_file.write(str(soup)) else: with open(cache_path, "r") as prev_cache_file: soup = BeautifulSoup(prev_cache_file, "lxml") return soup
def home(): return render_page(render_inline=True), 200
route = 'help' #string, representing RESTful endpoint name for this resource documentation_folder = 'doc' #string, representing WSGI application root folder name with API docs documentation_filename = 'Client API.md' #string representing name of 'documentation_folder' file with usage info help_path = os.path.join(documentation_folder, documentation_filename) #file path, to file with API usage info logger = logging.getLogger(__name__) #logger, for this module embed_css_in_html = True help_html = grip.render_page(path=help_path, render_inline=embed_css_in_html) class Help: """ Falcon resource object, providing API documentation """ def on_get(self, request, resp, **kwargs): """ Falcon resource method providing documentation """ resp.content_type = 'text/html; charset=utf-8' resp.body = help_html
def help(): print("help") return render_page()