Skip to content

Commit

Permalink
changed back to our customized python markdown2, since it's simpler a…
Browse files Browse the repository at this point in the history
…nd probably faster, and behaves exactly like Markdown.pl. This concludes issue #48
  • Loading branch information
MareoRaft committed Aug 7, 2017
1 parent 9d80795 commit d993a51
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions server/lib/helper.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import re
import random
import json
import tempfile
import subprocess
from os import path
from itertools import chain
from collections import OrderedDict
from copy import deepcopy

from lib.config import LIB_DIR
from lib import markdown2

def render_content(string):
""" see main.js for the original version of this function """
assert isinstance(string, str)
string = re.sub(r'\\', '\\\\', string) # g (global) is default

# protect \[ and \]
# protect \[ and \] from markdown
SLOSH_BRACKET_OPEN_STRING = r'Slosh-Bracket-Open-ry087qt3briuynpr98yn2p83ynriynr723nyr7ny2o3rn2083ry'
SLOSH_BRACKET_CLOSE_STRING = r'Slosh-Bracket-Close-ry087qt3briuynpr98yn2p83ynriynr723nyr7ny2o3rn2083ry'
string = re.sub(r'\\\[', SLOSH_BRACKET_OPEN_STRING, string)
string = re.sub(r'\\\]', SLOSH_BRACKET_CLOSE_STRING, string)

# run markdown server-side
tfile = tempfile.NamedTemporaryFile(mode='w+', suffix='.txt', prefix='prove-math-')
tfile.write(string)
tfile.flush()
fpath = tfile.name
markdown_path = path.join(LIB_DIR, 'Markdown.pl')
command = [markdown_path, fpath]
completed_process = subprocess.run(command, check=True, stdout=subprocess.PIPE)
tfile.close()
string = completed_process.stdout.decode()
string = markdown2.markdown(string, extras=["code-friendly", "underline"])
string = string.strip()

# re-enable \[ and \]
Expand Down

0 comments on commit d993a51

Please sign in to comment.