def __init__(self, name: str, markdown_text: str, css64: str = None, css_filename: str = None, *args, **kwargs): self.markdown_text = markdown_text self.md = markdown.Markdown( extensions=[mdx_gfm.GithubFlavoredMarkdownExtension()]) super(MarkdownWidget, self).__init__(name, *args, **kwargs) self.css64 = self.read_file(css_filename) self.css64 = self.css64 if self.css64 else css64 self.css_filename = css_filename
def _gen_sections(data): """ Yield each section in the provided document data. """ for (path, item) in da.util.walkobj(data, gen_nonleaf=True, gen_path=True, gen_obj=True): if '_metadata' in path: continue # All valid sections will have a _num field. try: section_num = item['_num'] except TypeError: continue # Not sure if this is relevant any more ... # What do we do with _req anyway??? if '_txt' in item: section_type = '_txt' elif '_req' in item: section_type = '_req' else: raise RuntimeError('Could not determine section type.') # Empty paragraphs. # (Remove here or in individual rendereds?) is_empty = (not item[section_type] or item[section_type] == 'TBD\n' or item[section_type] == 'NONE\n') if is_empty: paragraph_list = [] else: paragraph_list = [item[section_type]] # Convert github-flavour-markdown paragraphs to html, gfm_extn = mdx_gfm.GithubFlavoredMarkdownExtension() mkdn = markdown.Markdown(extensions=[gfm_extn]) html_list = [mkdn.convert(para) for para in paragraph_list] yield { 'level': section_num.count('.') + 1, 'title': path[-1].replace('_', ' ').capitalize(), 'num': section_num, 'type': section_type, 'para': paragraph_list, 'html': html_list }
import os def ext_change(fn, ext): return os.path.splitext(fn)[0] + ext import markdown import mdx_gfm mdext = mdx_gfm.GithubFlavoredMarkdownExtension() test = "" import codecs import re def md2html_file(mdfn, stylesheet): infile = codecs.open(mdfn, mode="r", encoding="utf-8") htmlfrag = markdown.markdown(infile.read(), output_format="html5", tab_length=2, extensions=[mdext]) infile.close() # href="*.md" -> href="*.html" htmlfrag = re.sub( r"(?<=href\=\")https://github\.com/(?P<usr>.+)/(?P<repo>.+)/blob/master/(?P<mdn>.+?)\.md(?=\")", r"https://\g<usr>.github.io/\g<repo>/\g<mdn>.html", htmlfrag) htmlfrag = re.sub(r"(?<=href\=\")(?P<mdn>[^:]*?)\.md(?=\")", r"\g<mdn>.html", htmlfrag) template = """<!doctype html>
html = res['html'] builderscon.cache.set(key, html, SESSION_SLIDE_EMBED_EXPIRES) return html html = '<a href="%s">%s</a>' % (url, url) builderscon.cache.set(key, html, SESSION_SLIDE_EMBED_EXPIRES) return html @builderscon.app.template_filter('confdate') def conference_date_filter(s, lang='en', timezone='UTC'): return model.ConferenceDate(s, lang=lang, timezone=timezone) markdown_converter = markdown.Markdown( extensions=[mdx_gfm.GithubFlavoredMarkdownExtension()]).convert @builderscon.app.template_filter('markdown') def markdown_filter(s): return markdown_converter(s) @builderscon.app.template_filter('audlevelname') def audience_level_value_to_name(v): if not v: return '' return v.title() # Used in templates, when all you have is the user's input value
AUTHOR_FEED_RSS = None # TOC Generator PLUGIN_PATHS = ['./theme/plugins'] PLUGINS = ['toc'] TOC_HEADERS = r"h[1-6]" # Blogroll LINKS = ( ('Pelican', 'http://getpelican.com/'), ('Python.org', 'http://python.org/'), ('Jinja2', 'http://jinja.pocoo.org/'), ('You can modify those links in your config file', '#'), ) # Social widget SOCIAL = ( ('You can add links in your config file', '#'), ('Another social link', '#'), ) DEFAULT_PAGINATION = False # Uncomment following line if you want document-relative URLs when developing #RELATIVE_URLS = True # Use GitHub Flavored Markdown MARKDOWN = { 'extensions': [mdx_gfm.GithubFlavoredMarkdownExtension()], }