diff --git a/gapic/utils/rst.py b/gapic/utils/rst.py index dd1d65d75d..0cac3e09f2 100644 --- a/gapic/utils/rst.py +++ b/gapic/utils/rst.py @@ -20,6 +20,13 @@ from gapic.utils.lines import wrap +import functools + +@functools.lru_cache(maxsize=None) +def _p(t, c, f): + return pypandoc.convert_text(t, "rst", format=f, verify_format=False, extra_args=["--columns=%d" % c]).strip() + + def rst( text: str, width: int = 72, @@ -55,18 +62,12 @@ def rst( width=width - indent, ) else: - # Convert from CommonMark to ReStructured Text. - answer = ( - pypandoc.convert_text( - text, - "rst", - format=source_format, - verify_format=False, - extra_args=["--columns=%d" % (width - indent)], - ) - .strip() - .replace("\n", f"\n{' ' * indent}") - ) + # Fast path for snake_case and other simple symbols + if not re.search(r"[*`]|(?