Skip to content

Commit ca40b72

Browse files
author
Benjamin Moody
committed
tinymce: add codetag (Code Tags) plugin.
This plugin adds a button and a keyboard shortcut for applying <code> style tags to text.
1 parent 8a5b5a3 commit ca40b72

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

physionet-django/physionet/settings/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,14 @@
460460
]),
461461
"external_plugins": {
462462
"pnmath": "/static/tinymce-plugins/pnmath.js",
463+
"codetag": "/static/tinymce-plugins/codetag.js",
463464
},
464465

465466
"pnmath_mathjax_url": "/static/mathjax/es5/",
466467

467468
"toolbar": (
468469
"undo redo | styles | "
469-
"bold italic math | "
470+
"bold italic codetag math | "
470471
"numlist bullist table | "
471472
"searchreplace removeformat code"
472473
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
tinymce.PluginManager.add('codetag', function(editor, url) {
2+
editor.ui.registry.addIcon('codetag', '<svg width="24" height="24"><rect x="8" y="6.75" width="2" height="10.5" ry=".75"/><rect x="9.75" y="17" width="5.5" height="2" ry=".75"/><rect x="15" y="6.75" width="2" height="2.5" ry=".75"/><rect x="9.75" y="5" width="5.5" height="2" ry=".75"/><rect x="15" y="14.75" width="2" height="2.5" ry=".75"/></svg>');
3+
4+
editor.ui.registry.addToggleButton('codetag', {
5+
icon: 'codetag',
6+
tooltip: 'Code',
7+
onAction: (_) => editor.execCommand('mceToggleFormat', false, 'code'),
8+
onSetup: (api) => {
9+
api.setActive(editor.formatter.match('code'));
10+
const changed = editor.formatter.formatChanged('code', (state) => api.setActive(state));
11+
return () => changed.unbind();
12+
}
13+
});
14+
15+
editor.addShortcut('meta+d', 'Code', () => {
16+
editor.execCommand('mceToggleFormat', false, 'code');
17+
});
18+
19+
return {
20+
getMetadata: () => ({
21+
name: 'Code Tags',
22+
url: 'https://github.com/MIT-LCP/physionet-build',
23+
})
24+
};
25+
});

0 commit comments

Comments
 (0)