fenced_code: Optimize FENCE_RE to fix cubic worst-case complexity.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-05-13 10:42:53 -07:00
committed by Alex Vandiver
parent ad858d2c79
commit 2df2f7eec6
4 changed files with 34 additions and 27 deletions

View File

@@ -69,8 +69,8 @@ from zerver.models import (
class SimulatedFencedBlockPreprocessor(FencedBlockPreprocessor):
# Simulate code formatting.
def format_code(self, lang: str, code: str) -> str:
return lang + ":" + code
def format_code(self, lang: Optional[str], code: str) -> str:
return (lang or "") + ":" + code
def placeholder(self, s: str) -> str:
return "**" + s.strip("\n") + "**"