File tree 5 files changed +31
-3
lines changed 5 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,8 @@ buttons.list.task.tooltip = Add a list of tasks
133
133
buttons.mention.tooltip = Mention a user or team
134
134
buttons.ref.tooltip = Reference an issue or pull request
135
135
buttons.switch_to_legacy.tooltip = Use the legacy editor instead
136
+ buttons.enable_monospace_font = Enable monospace font
137
+ buttons.disable_monospace_font = Disable monospace font
136
138
137
139
[filter]
138
140
string.asc = A - Z
Original file line number Diff line number Diff line change @@ -40,12 +40,23 @@ Template Attributes:
40
40
<md-ref class="markdown-toolbar-button" data-tooltip-content="{{.locale.Tr "editor.buttons.ref.tooltip"}}">{{svg "octicon-cross-reference"}}</md-ref>
41
41
</div>
42
42
<div class="markdown-toolbar-group">
43
+ <button class="markdown-toolbar-button markdown-switch-monospace" role="switch" data-enable-text="{{.locale.Tr "editor.buttons.enable_monospace_font"}}" data-disable-text="{{.locale.Tr "editor.buttons.disable_monospace_font"}}">{{svg "octicon-typography"}}</button>
43
44
<button class="markdown-toolbar-button markdown-switch-easymde" data-tooltip-content="{{.locale.Tr "editor.buttons.switch_to_legacy.tooltip"}}">{{svg "octicon-arrow-switch"}}</button>
44
45
</div>
45
46
</markdown-toolbar>
46
47
<text-expander keys=": @">
47
48
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}>{{.TextareaContent}}</textarea>
48
49
</text-expander>
50
+ <script>
51
+ const monospaceEnabled = localStorage?.getItem('editor-monospace') === 'true';
52
+ const btn = document.querySelector('.markdown-switch-monospace');
53
+ const text = btn.getAttribute(monospaceEnabled ? 'data-disable-text' : 'data-enable-text');
54
+ btn.setAttribute('data-tooltip-content', text);
55
+ btn.setAttribute('aria-checked', String(monospaceEnabled));
56
+ if (monospaceEnabled) {
57
+ document.querySelector('.markdown-text-editor').classList.add('gt-mono');
58
+ }
59
+ </script>
49
60
</div>
50
61
<div class="ui tab markup" data-tab-panel="markdown-previewer">
51
62
{{.locale.Tr "loading"}}
Original file line number Diff line number Diff line change 24
24
user-select : none;
25
25
padding : 5px ;
26
26
cursor : pointer;
27
+ border : none;
28
+ background : none;
29
+ color : var (--color-text );
27
30
}
28
31
29
32
.combo-markdown-editor .markdown-toolbar-button : hover {
Original file line number Diff line number Diff line change 29
29
30
30
.gt-mono {
31
31
font-family : var (--fonts-monospace ) !important ;
32
- font-size : .9 em !important ; /* compensate for monospace fonts being usually slightly larger */
32
+ font-size : .95 em !important ; /* compensate for monospace fonts being usually slightly larger */
33
33
}
34
34
35
35
.gt-bold { font-weight : 600 !important ; }
Original file line number Diff line number Diff line change @@ -73,8 +73,20 @@ class ComboMarkdownEditor {
73
73
// upstream bug: The role code is never executed in base MarkdownButtonElement https://github.com/github/markdown-toolbar-element/issues/70
74
74
el . setAttribute ( 'role' , 'button' ) ;
75
75
}
76
- this . switchToEasyMDEButton = this . container . querySelector ( '.markdown-switch-easymde' ) ;
77
- this . switchToEasyMDEButton ?. addEventListener ( 'click' , async ( e ) => {
76
+
77
+ const monospaceButton = this . container . querySelector ( '.markdown-switch-monospace' ) ;
78
+ monospaceButton ?. addEventListener ( 'click' , ( e ) => {
79
+ e . preventDefault ( ) ;
80
+ const enabled = localStorage ?. getItem ( 'editor-monospace' ) !== 'true' ;
81
+ localStorage . setItem ( 'editor-monospace' , String ( enabled ) ) ;
82
+ this . textarea . classList [ enabled ? 'add' : 'remove' ] ( 'gt-mono' ) ;
83
+ const text = monospaceButton . getAttribute ( enabled ? 'data-disable-text' : 'data-enable-text' ) ;
84
+ monospaceButton . setAttribute ( 'data-tooltip-content' , text ) ;
85
+ monospaceButton . setAttribute ( 'aria-checked' , String ( enabled ) ) ;
86
+ } ) ;
87
+
88
+ const easymdeButton = this . container . querySelector ( '.markdown-switch-easymde' ) ;
89
+ easymdeButton ?. addEventListener ( 'click' , async ( e ) => {
78
90
e . preventDefault ( ) ;
79
91
this . userPreferredEditor = 'easymde' ;
80
92
await this . switchToEasyMDE ( ) ;
You can’t perform that action at this time.
0 commit comments