11from __future__ import annotations
22
3- import functools
43import itertools
54import re
65from abc import ABC , abstractmethod
@@ -224,7 +223,7 @@ def __init__(self) -> None:
224223 ("*" , self ._format_bold ),
225224 ("_" , self ._format_italic ),
226225 ("``" , self ._format_code ),
227- ("" , functools . partial ( LinkFormatter ().format_link ) ),
226+ ("" , LinkFormatter ().format_link ),
228227 ]
229228
230229 def format (self , line : str ) -> str :
@@ -249,9 +248,10 @@ def _format_code(self, line: str) -> str:
249248 return self ._code .sub ("\\ 1`\\ 3`" , line )
250249
251250
252- class PreformattedFormatter ( Formatter ):
253- _format_line = functools . partial ( LineFormatter (). format )
251+ _line_formatter = LineFormatter ()
252+
254253
254+ class PreformattedFormatter (Formatter ):
255255 def _handles (self , line : str ) -> bool :
256256 return line .startswith ("| " ) or line == "|"
257257
@@ -261,8 +261,6 @@ def format(self, lines: List[str]) -> str:
261261
262262
263263class ParagraphFormatter (Formatter ):
264- _format_line = functools .partial (LineFormatter ().format )
265-
266264 def __init__ (self , other_formatters : List [Formatter ]) -> None :
267265 super ().__init__ ()
268266 self ._other_formatters = other_formatters
@@ -271,18 +269,17 @@ def _handles(self, line: str) -> bool:
271269 return not any (other .handles (line ) for other in self ._other_formatters )
272270
273271 def format (self , lines : List [str ]) -> str :
274- return self . _format_line (" " .join (lines )) + "\n \n "
272+ return _line_formatter . format (" " .join (lines )) + "\n \n "
275273
276274
277275class ListFormatter (Formatter ):
278276 _strip_lines = False
279- _format_item = functools .partial (LineFormatter ().format )
280277
281278 def _handles (self , line : str ) -> bool :
282279 return bool (line .strip ().startswith ("- " ) or line .startswith (" " ) and self ._lines )
283280
284281 def format (self , lines : List [str ]) -> str :
285- items = ["- %s" % self . _format_item (line ) for line in self ._combine_lines (lines )]
282+ items = ["- %s" % _line_formatter . format (line ) for line in self ._combine_lines (lines )]
286283 return "\n " .join (items ) + "\n \n "
287284
288285 def _combine_lines (self , lines : List [str ]) -> Iterator [str ]:
@@ -311,7 +308,7 @@ def format_line(self, line: str) -> str:
311308class TableFormatter (Formatter ):
312309 _table_line = re .compile (r"^\| (.* |)\|$" )
313310 _line_splitter = re .compile (r" \|(?= )" )
314- _format_cell_content = functools . partial ( LineFormatter (). format )
311+ _format_cell_content = _line_formatter . format
315312
316313 def _handles (self , line : str ) -> bool :
317314 return self ._table_line .match (line ) is not None
@@ -351,4 +348,4 @@ def _format_cell(self, content: str) -> str:
351348 if content .startswith ("=" ) and content .endswith ("=" ):
352349 content = content [1 :- 1 ]
353350
354- return f" { self . _format_cell_content (content ).strip ()} "
351+ return f" { _line_formatter . format (content ).strip ()} "
0 commit comments