Skip to content

Instantly share code, notes, and snippets.

@lukegb
Last active January 12, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukegb/cdc05021f72411d165f2 to your computer and use it in GitHub Desktop.
Save lukegb/cdc05021f72411d165f2 to your computer and use it in GitHub Desktop.
I'm sorry...
import json
from django.contrib.staticfiles import finders
import execjs
ctx = None
def load_mdit():
global ctx
if ctx:
return ctx
result = finders.find('bower_components/markdown-it/dist/markdown-it.js')
if not result:
raise ValueError("Unable to locate markdown-it - is Ore installed correctly?")
with open(result, 'r') as f:
mdit = f.read()
runtime = execjs.get()
ctx = runtime.compile("exports = undefined, module = undefined, define = undefined, window = {}; " + mdit)
return ctx
def compile(text, context={}):
ctx = load_mdit()
return ctx.eval("(new window.markdownit()).render(" + json.dumps({'v': text}) + ".v)")
@JamyDev
Copy link

JamyDev commented Jan 12, 2016

wat, why not just use NodeJS? :P

@lukegb
Copy link
Author

lukegb commented Jan 12, 2016

@JamyDev under the hood, execjs can. It defaults to trying to use PyV8, which I haven't managed to get to compile yet...

Sigh. I might just add a nodejs socket server whose only role in life is to render markdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment