File tree Expand file tree Collapse file tree 5 files changed +31
-3
lines changed Expand file tree Collapse file tree 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
133133buttons.mention.tooltip = Mention a user or team
134134buttons.ref.tooltip = Reference an issue or pull request
135135buttons.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
136138
137139[filter]
138140string.asc = A - Z
Original file line number Diff line number Diff line change @@ -40,12 +40,23 @@ Template Attributes:
4040 <md-ref class="markdown-toolbar-button" data-tooltip-content="{{.locale.Tr "editor.buttons.ref.tooltip"}}">{{svg "octicon-cross-reference"}}</md-ref>
4141 </div>
4242 <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>
4344 <button class="markdown-toolbar-button markdown-switch-easymde" data-tooltip-content="{{.locale.Tr "editor.buttons.switch_to_legacy.tooltip"}}">{{svg "octicon-arrow-switch"}}</button>
4445 </div>
4546 </markdown-toolbar>
4647 <text-expander keys=": @">
4748 <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>
4849 </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>
4960 </div>
5061 <div class="ui tab markup" data-tab-panel="markdown-previewer">
5162 {{.locale.Tr "loading"}}
Original file line number Diff line number Diff line change 2424 user-select : none;
2525 padding : 5px ;
2626 cursor : pointer;
27+ border : none;
28+ background : none;
29+ color : var (--color-text );
2730}
2831
2932.combo-markdown-editor .markdown-toolbar-button : hover {
Original file line number Diff line number Diff line change 2929
3030.gt-mono {
3131 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 */
3333}
3434
3535.gt-bold { font-weight : 600 !important ; }
Original file line number Diff line number Diff line change @@ -73,8 +73,20 @@ class ComboMarkdownEditor {
7373 // upstream bug: The role code is never executed in base MarkdownButtonElement https://github.com/github/markdown-toolbar-element/issues/70
7474 el . setAttribute ( 'role' , 'button' ) ;
7575 }
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 ) => {
7890 e . preventDefault ( ) ;
7991 this . userPreferredEditor = 'easymde' ;
8092 await this . switchToEasyMDE ( ) ;
You can’t perform that action at this time.
0 commit comments