Last active
January 12, 2016 17:20
-
-
Save lukegb/cdc05021f72411d165f2 to your computer and use it in GitHub Desktop.
I'm sorry...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
wat, why not just use NodeJS? :P