fix nested codeblock escaping
This commit is contained in:
parent
514bf7ac93
commit
b89f4e83fd
6
main.py
6
main.py
@ -109,6 +109,10 @@ def fix_nesting_code_blocks(content):
|
||||
return '\n'.join(out)
|
||||
|
||||
|
||||
def fix_code_block_content(content):
|
||||
return content.replace(r'\_', '_').replace(r'\*', '*')
|
||||
|
||||
|
||||
def trim_code_blocks(content):
|
||||
codeblock_regex = re.compile(r'```(.+?)```', re.DOTALL)
|
||||
pos = 0
|
||||
@ -116,7 +120,7 @@ def trim_code_blocks(content):
|
||||
while m := codeblock_regex.search(content, pos):
|
||||
out = out + content[pos:m.start()].strip()
|
||||
parts = re.split(r'[\n\r ]', m.group(1), 1)
|
||||
out = out + '\n\n```' + parts[0].strip() + '\n' + parts[1].strip() + '\n```\n\n'
|
||||
out = out + '\n\n```' + parts[0].strip() + '\n' + fix_code_block_content(parts[1]).strip() + '\n```\n\n'
|
||||
pos = m.end()
|
||||
return out + content[pos:].strip()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user