@@ -63,7 +63,6 @@ def __init__(self, master, **kwargs):
63
63
self .bold_btn .pack (side = "left" , padx = 0 , pady = 0 )
64
64
self .italic_btn = tk .Button (self .top_bar , text = "Italic" , command = lambda : self .check_bold_italic (constants .italic_md_syntax , constants .italic_md_ignore , constants .italic_md_special ))
65
65
self .italic_btn .pack (side = "left" , padx = 0 , pady = 0 )
66
- # # Currently has issues, needs constants adjusting.
67
66
self .bold_italic_btn = tk .Button (self .top_bar , text = "Bold Italic" , command = lambda : self .check_bold_italic (constants .bold_italic_md_syntax , constants .bold_italic_md_ignore , constants .bold_italic_md_special ))
68
67
self .bold_italic_btn .pack (side = "left" , padx = 0 , pady = 0 )
69
68
# self.heading_btn = tk.Button(self.top_bar, text="Heading")
@@ -353,6 +352,7 @@ def apply_markdown_both_sides(self, selection, md_syntax):
353
352
"""Apply markdown to both sides of a selection.
354
353
355
354
Args:
355
+ selection (str): Text selection from the editor.
356
356
md_syntax (tuple): Tuple of markdown strings to apply.
357
357
"""
358
358
self .md_syntax = md_syntax
@@ -366,6 +366,7 @@ def remove_markdown_both_sides(self, selection, md_syntax):
366
366
"""Remove markdown from both sides of a selection.
367
367
368
368
Args:
369
+ selection (str): Text selection from the editor.
369
370
md_syntax (tuple): Tuple of markdown strings to remove.
370
371
"""
371
372
self .md_syntax = md_syntax
@@ -376,20 +377,34 @@ def remove_markdown_both_sides(self, selection, md_syntax):
376
377
return
377
378
378
379
def check_bold_italic (self , md_syntax , md_ignore , md_special ):
380
+ """Specific checks for bold, italic and bold-italic markdown syntax.
381
+
382
+ This will ignore items in the md_ignore variable and then deal with
383
+ special syntax individually before applying or removing the markdown
384
+ formatting.
385
+
386
+ - If string starts with anything in md_ignore do
387
+ nothing and return from the function.
388
+ - If the formatting requires special items which can't go in md_ignore
389
+ because they cause issues with markdown being applied incorrectly do
390
+ nothing and return from the function.
391
+ - Apply or remove the markdown once we reach the end.
392
+
393
+ Args:
394
+ selection (str): Text selection from the editor.
395
+ md_syntax (tuple): Tuple of markdown strings to remove.
396
+ md_ignore (tuple): Tuple of markdown strings to ignore.
397
+ md_special (tuple): Tuple of special markdown strings to ignore that
398
+ cause unexpected issues when included in md_ignore.
399
+ """
379
400
self .md_syntax = md_syntax
380
401
self .md_ignore = md_ignore
381
402
self .md_special = md_special
382
403
self .cur_selection = self .text_area .selection_get ()
383
- # Ignore items in the md_ignore variable and then deal with special
384
- # syntax individually. If string starts with anything in md_ignore do
385
- # nothing and return from the function.
386
404
if str (self .cur_selection ).startswith (self .md_ignore ) or str (self .cur_selection ).endswith (self .md_ignore ):
387
405
return
388
- # If the formatting requires special items which can't go in md_ignore
389
- # because they cause issues with markdown being applied incorrectly.
390
406
elif str (self .cur_selection ).startswith (self .md_special ) and str (self .cur_selection ).endswith (self .md_special ) and not str (self .cur_selection ).startswith (self .md_syntax ) and not str (self .cur_selection ).startswith (self .md_syntax ):
391
- return
392
- # Apply or remove the markdown once we reach this stage.
407
+ return
393
408
elif str (self .cur_selection ).startswith (self .md_syntax ) and str (self .cur_selection ).endswith (self .md_syntax ):
394
409
self .remove_markdown_both_sides (self .cur_selection , self .md_syntax )
395
410
else :
0 commit comments