This repository was archived by the owner on Mar 26, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed
Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change 1717
1818import pypandoc # type: ignore
1919
20+ import functools
21+
2022from gapic .utils .lines import wrap
2123
24+ @functools .lru_cache (maxsize = 2048 )
25+ def _convert_pandoc (text : str , columns : int , source_format : str ) -> str :
26+ """Cached helper to run pypandoc with specific column width.
27+
28+ Args:
29+ columns: Must be positive. Enforced by caller.
30+ """
31+ return pypandoc .convert_text (text , 'rst' ,
32+ format = source_format ,
33+ extra_args = ['--columns=%d' % columns ],
34+ ).strip ()
35+
36+
2237
2338def rst (
2439 text : str ,
@@ -56,17 +71,11 @@ def rst(
5671 )
5772 else :
5873 # Convert from CommonMark to ReStructured Text.
59- answer = (
60- pypandoc .convert_text (
61- text ,
62- "rst" ,
63- format = source_format ,
64- verify_format = False ,
65- extra_args = ["--columns=%d" % (width - indent )],
66- )
67- .strip ()
68- .replace ("\n " , f"\n { ' ' * indent } " )
69- )
74+ answer = _convert_pandoc (
75+ str (text ),
76+ width - indent ,
77+ str (source_format )
78+ ).replace ('\n ' , f"\n { ' ' * indent } " )
7079
7180 # Add a newline to the end of the document if any line breaks are
7281 # already present.
You can’t perform that action at this time.
0 commit comments