2727from mdutils .tools .TextUtils import TextUtils
2828from mdutils .tools .MDList import MDList , MDCheckbox
2929from textwrap import fill
30+ from typing import Union , Optional , List
3031
3132
3233class MdUtils :
@@ -44,7 +45,7 @@ class MdUtils:
4445 - **file_data_text:** contains all the file data that will be written on the markdown file.
4546 """
4647
47- def __init__ (self , file_name , title = "" , author = "" ):
48+ def __init__ (self , file_name : str , title : str = '' , author : str = '' ):
4849 """
4950
5051 :param file_name: it is the name of the Markdown file.
@@ -65,7 +66,7 @@ def __init__(self, file_name, title="", author=""):
6566 self .reference = Reference ()
6667 self .image = Image (reference = self .reference )
6768
68- def create_md_file (self ):
69+ def create_md_file (self ) -> MarkDownFile :
6970 """It creates a new Markdown file.
7071 :return: return an instance of a MarkDownFile."""
7172 md_file = MarkDownFile (self .file_name )
@@ -80,7 +81,7 @@ def get_md_text(self) -> str:
8081 :return: return a string with the markdown text."""
8182 return self .title + self .table_of_contents + self .file_data_text + self .reference .get_references_as_markdown ()
8283
83- def read_md_file (self , file_name ) :
84+ def read_md_file (self , file_name : str ) -> str :
8485 """Reads a Markdown file and save it to global class `file_data_text`.
8586
8687 :param file_name: Markdown file's name that has to be read.
@@ -93,7 +94,7 @@ def read_md_file(self, file_name):
9394
9495 return file_data
9596
96- def new_header (self , level , title , style = 'atx' , add_table_of_contents = 'y' , header_id = '' ):
97+ def new_header (self , level : int , title : str , style : str = 'atx' , add_table_of_contents : str = 'y' , header_id : str = '' ) -> str :
9798 """Add a new header to the Markdown file.
9899
99100 :param level: Header level. *atx* style can take values 1 til 6 and *setext* style take values 1 and 2.
@@ -122,7 +123,7 @@ def new_header(self, level, title, style='atx', add_table_of_contents='y', heade
122123 self .___update_file_data (self .header .choose_header (level , title , style , header_id ))
123124 return self .header .choose_header (level , title , style , header_id )
124125
125- def __add_new_item_table_of_content (self , level , item ):
126+ def __add_new_item_table_of_content (self , level : int , item : Union [ List [ str ], str ] ):
126127 """Automatically add new atx headers to the table of contents.
127128
128129 :param level: add levels up to 6.
@@ -143,7 +144,7 @@ def __add_new_item_table_of_content(self, level, item):
143144 curr .append ([])
144145
145146
146- def new_table_of_contents (self , table_title = "Table of contents" , depth = 1 , marker = '' ):
147+ def new_table_of_contents (self , table_title : str = "Table of contents" , depth : int = 1 , marker : str = '' ) -> str :
147148 """Table of contents can be created if Headers of 'atx' style have been defined.
148149
149150 This method allows to create a table of contents and define a title for it. Moreover, `depth` allows user to
@@ -175,7 +176,7 @@ def new_table_of_contents(self, table_title="Table of contents", depth=1, marker
175176
176177 return self .table_of_contents + marker_table_of_contents
177178
178- def new_table (self , columns , rows , text , text_align = 'center' , marker = '' ):
179+ def new_table (self , columns : int , rows : int , text : List [ str ] , text_align : str = 'center' , marker : str = '' ) -> str :
179180 """This method takes a list of strings and creates a table.
180181
181182 Using arguments ``columns`` and ``rows`` allows to create a table of *n* columns and *m* rows. The
@@ -222,7 +223,7 @@ def new_table(self, columns, rows, text, text_align='center', marker=''):
222223
223224 return text_table
224225
225- def new_paragraph (self , text = '' , bold_italics_code = '' , color = 'black' , align = '' , wrap_width = 0 ) :
226+ def new_paragraph (self , text : str = '' , bold_italics_code : str = '' , color : str = 'black' , align : str = '' , wrap_width : int = 0 ) -> str :
226227 """Add a new paragraph to Markdown file. The text is saved to the global variable file_data_text.
227228
228229 :param text: is a string containing the paragraph text. Optionally, the paragraph text is returned.
@@ -252,7 +253,7 @@ def new_paragraph(self, text='', bold_italics_code='', color='black', align='',
252253
253254 return self .file_data_text
254255
255- def new_line (self , text = '' , bold_italics_code = '' , color = 'black' , align = '' , wrap_width = 0 ) :
256+ def new_line (self , text : str = '' , bold_italics_code : str = '' , color : str = 'black' , align : str = '' , wrap_width : int = 0 ) -> str :
256257 """Add a new line to Markdown file. The text is saved to the global variable file_data_text.
257258
258259 :param text: is a string containing the paragraph text. Optionally, the paragraph text is returned.
@@ -281,7 +282,7 @@ def new_line(self, text='', bold_italics_code='', color='black', align='', wrap_
281282
282283 return self .file_data_text
283284
284- def write (self , text = '' , bold_italics_code = '' , color = 'black' , align = '' , marker = '' , wrap_width = 0 ) :
285+ def write (self , text : str = '' , bold_italics_code : str = '' , color : str = 'black' , align : str = '' , marker : str = '' , wrap_width : int = 0 ) -> str :
285286 """Write text in ``file_Data_text`` string.
286287
287288 :param text: a text a string.
@@ -314,7 +315,7 @@ def write(self, text='', bold_italics_code='', color='black', align='', marker='
314315
315316 return new_text
316317
317- def insert_code (self , code , language = '' ):
318+ def insert_code (self , code : str , language : str = '' ) -> str :
318319 """This method allows to insert a peace of code on a markdown file.
319320
320321 :param code: code string.
@@ -328,7 +329,7 @@ def insert_code(self, code, language=''):
328329 self .___update_file_data (md_code )
329330 return md_code
330331
331- def create_marker (self , text_marker ) :
332+ def create_marker (self , text_marker : str ) -> str :
332333 """This will add a marker to ``file_data_text`` and returns the marker result in order to be used whenever
333334 you need.
334335
@@ -345,7 +346,7 @@ def create_marker(self, text_marker):
345346 self .___update_file_data (new_marker )
346347 return new_marker
347348
348- def place_text_using_marker (self , text , marker ) :
349+ def place_text_using_marker (self , text : str , marker : str ) -> str :
349350 """It replace a previous marker created with ``create_marker`` with a text string.
350351
351352 This method is going to search for the ``marker`` argument, which has been created previously using
@@ -363,7 +364,7 @@ def place_text_using_marker(self, text, marker):
363364 def ___update_file_data (self , file_data ):
364365 self .file_data_text += file_data
365366
366- def new_inline_link (self , link , text = None , bold_italics_code = '' , align = '' ):
367+ def new_inline_link (self , link : str , text : Optional [ str ] = None , bold_italics_code : str = '' , align : str = '' ) -> str :
367368 """Creates a inline link in markdown format.
368369
369370 :param link:
@@ -392,7 +393,7 @@ def new_inline_link(self, link, text=None, bold_italics_code='', align=''):
392393
393394 return Inline .new_link (link = link , text = n_text )
394395
395- def new_reference_link (self , link , text , reference_tag = None , bold_italics_code = '' , align = '' ):
396+ def new_reference_link (self , link : str , text : str , reference_tag : Optional [ str ] = None , bold_italics_code : str = '' , align : str = '' ) -> str :
396397 """Creates a reference link in markdown format. All references will be stored at the end of the markdown file.
397398
398399
@@ -444,7 +445,7 @@ def new_reference_link(self, link, text, reference_tag=None, bold_italics_code='
444445 return self .reference .new_link (link = link , text = n_text , reference_tag = reference_tag )
445446
446447 @staticmethod
447- def new_inline_image (text , path ) :
448+ def new_inline_image (text : str , path : str ) -> str :
448449 """Add inline images in a markdown file. For example ``[MyImage](../MyImage.jpg)``.
449450
450451 :param text: Text that is going to be displayed in the markdown file as a iamge.
@@ -458,7 +459,7 @@ def new_inline_image(text, path):
458459
459460 return Image .new_inline_image (text = text , path = path )
460461
461- def new_reference_image (self , text , path , reference_tag = None ):
462+ def new_reference_image (self , text : str , path : str , reference_tag : Optional [ str ] = None ) -> str :
462463 """Add reference images in a markdown file. For example ``[MyImage][my_image]``. All references will be stored
463464 at the end of the markdown file.
464465
@@ -476,7 +477,7 @@ def new_reference_image(self, text, path, reference_tag=None):
476477 """
477478 return self .image .new_reference_image (text = text , path = path , reference_tag = reference_tag )
478479
479- def new_list (self , items : [str ], marked_with : str = "-" ):
480+ def new_list (self , items : List [str ], marked_with : str = "-" ):
480481 """Add unordered or ordered list in MarkDown file.
481482
482483 :param items: Array of items for generating the list.
@@ -489,7 +490,7 @@ def new_list(self, items: [str], marked_with: str = "-"):
489490 mdlist = MDList (items , marked_with )
490491 self .___update_file_data ('\n ' + mdlist .get_md ())
491492
492- def new_checkbox_list (self , items : [str ], checked : bool = False ):
493+ def new_checkbox_list (self , items : List [str ], checked : bool = False ):
493494 """Add checkbox list in MarkDown file.
494495
495496 :param items: Array of items for generating the checkbox list.
0 commit comments