def _parse_meta(self, header, body): header = m.html(to_unicode(header)) titles = re.findall(r'<h1>(.*)</h1>', header) if not titles: logging.error('There is no title') title = None else: title = titles[0] meta = {'title': title} items = re.findall(r'<li>(.*?)</li>', header, re.S) for item in items: index = item.find(':') key = item[:index].rstrip() value = item[index + 1:].lstrip() meta[key] = value desc = re.findall(r'<p>(.*?)</p>', header, re.S) if desc: meta['description'] = '\n\n'.join(desc) #: keep body in meta data as source text meta['source_text'] = body _toc = m.Markdown(m.HtmlTocRenderer(), 0) meta['toc'] = _toc.render(body) return meta
def docs(docfile): toc = ['intro', 'install', 'gettingstarted', 'advanced', 'contributing'] titles = { 'intro': 'Introduction', 'install': 'Installation', 'gettingstarted': 'Getting Started', 'advanced': 'Advanced Usage', 'contributing': 'Contributing' } docs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'docs')) source_path = os.path.abspath(os.path.join(docs_dir, '%s.md' % docfile)) # Check just in case somehow a path outside docs dir is constructed if not source_path.startswith(docs_dir): abort(404) try: with open(source_path) as mf: content = hoedown.html(mf.read()) prev_i = toc.index(docfile) - 1 prev = toc[prev_i] if prev_i >= 0 else None next_i = toc.index(docfile) + 1 next = toc[next_i] if next_i < len(toc) else None return render_template('docs.html', current=docfile, prev=prev, next=next, content=content, toc=toc, titles=titles) except IOError: abort(404)
def docs(docfile): toc = [ 'intro', 'install', 'gettingstarted', 'reading', 'records', 'tokenization', 'pos', 'cem', 'lexicon', 'abbreviations', 'cli', 'scrape', 'contributing' ] titles = { 'intro': 'Introduction', 'install': 'Installation', 'gettingstarted': 'Getting Started', 'reading': 'Reading Documents', 'records': 'Chemical Records', 'tokenization': 'Tokenization', 'pos': 'Part-of-speech Tagging', 'cem': 'Chemical Named Entities', 'lexicon': 'Lexicon', 'abbreviations': 'Abbreviation Detection', 'cli': 'Command Line Interface', 'scrape': 'Scraping Structured Data', 'contributing': 'Contributing' } docs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'docs')) source_path = os.path.abspath(os.path.join(docs_dir, '%s.md' % docfile)) # Check just in case somehow a path outside docs dir is constructed if not source_path.startswith(docs_dir): abort(404) try: with open(source_path) as mf: content = hoedown.html(mf.read().decode('utf-8')) prev_i = toc.index(docfile) - 1 prev = toc[prev_i] if prev_i >= 0 else None next_i = toc.index(docfile) + 1 next = toc[next_i] if next_i < len(toc) else None return render_template('docs.html', current=docfile, prev=prev, next=next, content=content, toc=toc, titles=titles) except IOError: abort(404)
def markdown(text): text = FS_RE.sub(fs_replace, text) return markupsafe.Markup(hoedown.html( text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS))
def markdown(text): return markupsafe.Markup( hoedown.html(text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS))
def markdown(content): return hoedown.html(content, extensions=hoedown.EXT_FENCED_CODE | hoedown.EXT_HIGHLIGHT | hoedown.EXT_AUTOLINK | hoedown.EXT_TABLES | hoedown.EXT_STRIKETHROUGH | hoedown.EXT_UNDERLINE)
def setup(self): self.r = lambda html: hoedown.html(html, render_flags=HTML_SMARTYPANTS)