Skip to content

Commit 891761c

Browse files
zhngjanianding1
authored andcommitted
fix Chinese comment wrong rendered in code.
1 parent 2e00041 commit 891761c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

autoload/leetcode.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,10 @@ def get_submission(sid):
525525

526526
# the punctuations and newlines in the code are escaped like '\\u0010' ('\\' => real backslash)
527527
# to unscape the string, we do the trick '\\u0010'.encode().decode('unicode_escape') ==> '\n'
528-
submission['code'] = _break_code_lines(_unescape(_group1(
529-
re.search("submissionCode: '([^']*)'", s), '')))
528+
# submission['code'] = _break_code_lines(_unescape(_group1(
529+
# re.search("submissionCode: '([^']*)'", s), '')))
530+
submission['code'] = _unescape_with_Chinese(
531+
_group1(re.search("submissionCode: '([^']*)'", s), ''))
530532

531533
dist_str = _unescape(_group1(re.search("runtimeDistributionFormatted: '([^']*)'", s),
532534
'{"distribution":[]}'))
@@ -765,5 +767,15 @@ def _echoerr(s):
765767
print(s)
766768

767769

770+
def _unescape_with_Chinese(code) :
771+
for ch in set(re.findall(r'\\u\w{4}', code)):
772+
print(ch)
773+
code = code.replace(ch, ch.encode('utf-8').decode('unicode_escape'))
774+
log.info("code is %s", code)
775+
return code.splitlines()
776+
777+
778+
779+
768780
task_thread = Thread(target=_thread_main, daemon=True)
769781
task_thread.start()

0 commit comments

Comments
 (0)