@@ -64,16 +64,16 @@ def __init__(self, master, **kwargs):
64
64
self .paste_btn .pack (side = "left" , padx = 0 , pady = 0 )
65
65
self .find_btn = tk .Button (self .top_bar , text = "Find" , command = self .find )
66
66
self .find_btn .pack (side = "left" , padx = 0 , pady = 0 )
67
- self .bold_btn = tk .Button (self .top_bar , text = "Bold" , command = lambda : self .check_bold_italic (constants .bold_md_syntax , constants .bold_md_ignore , constants .bold_md_special ))
67
+ self .bold_btn = tk .Button (self .top_bar , text = "Bold" , command = lambda : self .check_markdown_both_sides (constants .bold_md_syntax , constants .bold_md_ignore , constants .bold_md_special ))
68
68
self .bold_btn .pack (side = "left" , padx = 0 , pady = 0 )
69
- 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 ))
69
+ self .italic_btn = tk .Button (self .top_bar , text = "Italic" , command = lambda : self .check_markdown_both_sides (constants .italic_md_syntax , constants .italic_md_ignore , constants .italic_md_special ))
70
70
self .italic_btn .pack (side = "left" , padx = 0 , pady = 0 )
71
- 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 ))
71
+ self .bold_italic_btn = tk .Button (self .top_bar , text = "Bold Italic" , command = lambda : self .check_markdown_both_sides (constants .bold_italic_md_syntax , constants .bold_italic_md_ignore , constants .bold_italic_md_special ))
72
72
self .bold_italic_btn .pack (side = "left" , padx = 0 , pady = 0 )
73
+ self .strikethrough_btn = tk .Button (self .top_bar , text = "Strikethrough" , command = lambda : self .check_markdown_both_sides (constants .strikethrough_md_syntax , constants .strikethrough_md_ignore , md_special = None , strikethrough = True ))
74
+ self .strikethrough_btn .pack (side = "left" , padx = 0 , pady = 0 )
73
75
# self.heading_btn = tk.Button(self.top_bar, text="Heading")
74
76
# self.heading_btn.pack(side="left", padx=0, pady=0)
75
- # self.strikethrough_btn = tk.Button(self.top_bar, text="Strikethrough")
76
- # self.strikethrough_btn.pack(side="left", padx=0, pady=0)
77
77
# self.unordered_list_btn = tk.Button(self.top_bar, text="Unordered List")
78
78
# self.unordered_list_btn.pack(side="left", padx=0, pady=0)
79
79
# self.ordered_list_btn = tk.Button(self.top_bar, text="Ordered List")
@@ -363,13 +363,13 @@ def load_style(self, stylename):
363
363
# print(self.style.background_color or 'white', self.text_area.tag_cget("Token.Text", "foreground") or 'black', stylename)
364
364
self .text_area .configure (bg = self .style .background_color or 'white' ,
365
365
fg = self .text_area .tag_cget ("Token.Text" , "foreground" ) or 'black' ,
366
- selectbackground = self .style .highlight_color
366
+ selectbackground = self .style .highlight_color ,
367
367
)
368
368
self .text_area .tag_configure (str (Generic .StrongEmph ), font = ('Monospace' , 10 , 'bold' , 'italic' ))
369
369
self .syntax_highlighting_tags .append (str (Generic .StrongEmph ))
370
370
self .css = 'body {background-color: %s; color: %s}' % (
371
371
self .style .background_color or 'white' ,
372
- self .text_area .tag_cget ("Token.Text" , "foreground" ) or 'black'
372
+ self .text_area .tag_cget ("Token.Text" , "foreground" ) or 'black' ,
373
373
)# used string%interpolation here because f'string' interpolation is too annoying with embeded { and }
374
374
self .preview_area .add_css (self .css )
375
375
return self .syntax_highlighting_tags
@@ -419,7 +419,7 @@ def remove_markdown_both_sides(self, selection, md_syntax):
419
419
self .text_area .insert (INSERT , self .remove_md )
420
420
return
421
421
422
- def check_bold_italic (self , md_syntax , md_ignore , md_special ):
422
+ def check_markdown_both_sides (self , md_syntax , md_ignore , md_special , strikethrough = None ):
423
423
"""Specific checks for bold, italic and bold-italic markdown syntax.
424
424
425
425
This will ignore items in the md_ignore variable and then deal with
@@ -446,6 +446,13 @@ def check_bold_italic(self, md_syntax, md_ignore, md_special):
446
446
self .cur_selection = self .text_area .selection_get ()
447
447
if str (self .cur_selection ).startswith (self .md_ignore ) or str (self .cur_selection ).endswith (self .md_ignore ):
448
448
return
449
+ elif strikethrough == True :
450
+ if str (self .cur_selection ).startswith (self .md_syntax ) and str (self .cur_selection ).endswith (self .md_syntax ):
451
+ self .remove_markdown_both_sides (self .cur_selection , self .md_syntax )
452
+ return
453
+ else :
454
+ self .apply_markdown_both_sides (self .cur_selection , self .md_syntax )
455
+ return
449
456
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 ):
450
457
return
451
458
elif str (self .cur_selection ).startswith (self .md_syntax ) and str (self .cur_selection ).endswith (self .md_syntax ):
0 commit comments