def build_html_output(content, node): return markdown.markdown( content, extensions=[ wikilinks.WikiLinkExtension( configs=[('base_url', ''), ( 'end_url', ''), ('build_url', functools.partial(build_wiki_url, node))]), fenced_code.FencedCodeExtension(), codehilite.CodeHiliteExtension([('css_class', 'highlight')]) ])
def servefile(self, dir, name): self.logger.critical('looking for ' + name + ' in ' + dir) # No caching self.set_header('Cache-control', 'no-cache, no-store, must-revalidate') # if the name ends with a slash remove it if name.endswith('/'): name = name[:-1] # make the filename by appending .md, the markdown suffix mdname = name + '.md' # try to find it in the datapath and subdir. file = os.path.join(datapath, dir, mdname) if os.path.exists(file): # found it, so this isn't a default page isdefault = False else: # can't find it in the current dir - is it in the default pages? file = os.path.join(resource_filename(__name__, 'defaults'), mdname) isdefault = True if not os.path.exists(file): # oops. self.logger.critical("cannot find file: " + file) return self.render_string('404.html', name=name, d=getdirprefix(dir)) # we have the file, load it. text = codecs.open(file, mode="r", encoding="utf-8").read() # process the markdown with some extensions. Our own extension will # store some data created during processing, so keep a reference to it. # Note that we change directory so any links should come out # right.. ext = GronkExtensions(name) html = markdown.markdown( text, extensions=[wikilinks.WikiLinkExtension(end_url=''), ext]) self.logger.info("************************** NODE SERVED: " + name) # now process and return the template, passing in the name, # whether it's a default, the navs and title built from the extension, # and the raw html which came from the markdown. These will # visible to the template. return self.render_string('main.html', name=name, isdefault=isdefault, navs=ext.navs, d=getdirprefix(dir), title=ext.title, content=html)
def render_content(content, node): html_output = markdown.markdown( content, extensions=[ wikilinks.WikiLinkExtension( configs=[('base_url', ''), ( 'end_url', ''), ('build_url', functools.partial(build_wiki_url, node))]), fenced_code.FencedCodeExtension(), codehilite.CodeHiliteExtension([('css_class', 'highlight')]) ]) # linkify gets called after santize, because we're adding rel="nofollow" # to <a> elements - but don't want to allow them for other elements. sanitized_content = sanitize(html_output, **settings.WIKI_WHITELIST) return sanitized_content
def render_to_html_string(self): """ Render the watched document to html, returning the html string :return: The rendered HTML of the markdown file """ self.logger.debug('Rendering markdown (%s)', self.filename) fake_file = BytesIO() markdown.markdownFromFile(input=self.filename, output=fake_file, extensions=[abbr.AbbrExtension(), admonition.AdmonitionExtension(), attr_list.AttrListExtension(), codehilite.CodeHiliteExtension(), def_list.DefListExtension(), extra.ExtraExtension(), fenced_code.FencedCodeExtension(), footnotes.FootnoteExtension(), legacy_attrs.LegacyAttrExtension(), legacy_em.LegacyEmExtension(), meta.MetaExtension(), nl2br.Nl2BrExtension(), sane_lists.SaneListExtension(), smarty.SmartyExtension(), tables.TableExtension(), toc.TocExtension(), wikilinks.WikiLinkExtension()]) fake_file.seek(0) return str(fake_file.read(), 'utf-8')
from dli_app import db from dli_app import mail from dli_app import flash_form_errors from dli_app.mod_wiki.models import WikiPage from dli_app.mod_wiki.forms import EditWikiPageForm from dli_app.mod_wiki.forms import SearchForm from dli_app.mod_wiki.forms import AskQuestionForm EXTENSIONS = [ extra.ExtraExtension(), nl2br.Nl2BrExtension(), toc.TocExtension(), wikilinks.WikiLinkExtension(base_url='/wiki/'), ] MD = Markdown(extensions=EXTENSIONS) # Create a blueprint for this module mod_wiki = Blueprint('wiki', __name__, url_prefix='/wiki') # Set all routing for the module @mod_wiki.route('/', methods=['GET']) @mod_wiki.route('/home', methods=['GET']) @mod_wiki.route('/home/', methods=['GET']) def home(): """Render the wiki homepage""" pages = WikiPage.query.order_by(WikiPage.views.desc()).limit(10).all()