Skip to content

Commit

Permalink
protect \[ and \] from markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MareoRaft committed Aug 7, 2017
1 parent 0c104d7 commit 9d80795
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def render_content(string):
assert isinstance(string, str)
string = re.sub(r'\\', '\\\\', string) # g (global) is default

# protect \[ and \]
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)
Expand All @@ -27,6 +33,10 @@ def render_content(string):
string = completed_process.stdout.decode()
string = string.strip()

# re-enable \[ and \]
string = re.sub(SLOSH_BRACKET_OPEN_STRING, '\\[', string)
string = re.sub(SLOSH_BRACKET_CLOSE_STRING, '\\]', string)

# enable images
string = re.sub(r'img(\d+)', '<img src="image/$1.jpg" />', string)
string = re.sub(r'\\includegraphics\{(.*?)\}', '<img src="image/$1.jpg" />', string)
Expand Down

0 comments on commit 9d80795

Please sign in to comment.