Skip to content

Commit

Permalink
tinymce: add codetag (Code Tags) plugin.
Browse files Browse the repository at this point in the history
This plugin adds a button and a keyboard shortcut for applying <code>
style tags to text.
  • Loading branch information
Benjamin Moody committed Feb 5, 2025
1 parent ebd93c3 commit be5a5c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion physionet-django/physionet/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,14 @@
]),
"external_plugins": {
"pnmath": "/static/tinymce-plugins/pnmath.js",
"codetag": "/static/tinymce-plugins/codetag.js",
},

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

"toolbar": (
"undo redo | styles | "
"bold italic math | "
"bold italic codetag math | "
"numlist bullist table | "
"searchreplace code restoredraft"
),
Expand Down
25 changes: 25 additions & 0 deletions physionet-django/static/tinymce-plugins/codetag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tinymce.PluginManager.add('codetag', function(editor, url) {
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>');

editor.ui.registry.addToggleButton('codetag', {
icon: 'codetag',
tooltip: 'Code',
onAction: (_) => editor.execCommand('mceToggleFormat', false, 'code'),
onSetup: (api) => {
api.setActive(editor.formatter.match('code'));
const changed = editor.formatter.formatChanged('code', (state) => api.setActive(state));
return () => changed.unbind();
}
});

editor.addShortcut('meta+d', 'Code', () => {
editor.execCommand('mceToggleFormat', false, 'code');
});

return {
getMetadata: () => ({
name: 'Code Tags',
url: 'https://github.com/MIT-LCP/physionet-build',
})
};
});

0 comments on commit be5a5c8

Please sign in to comment.