diff --git a/main.py b/main.py index 2a4fab9..f8b7608 100644 --- a/main.py +++ b/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()