diff --git a/packages/app-cli/tests/support/plugins/content_script/src/index.ts b/packages/app-cli/tests/support/plugins/content_script/src/index.ts index c7ed3d092..1fb7038fb 100644 --- a/packages/app-cli/tests/support/plugins/content_script/src/index.ts +++ b/packages/app-cli/tests/support/plugins/content_script/src/index.ts @@ -3,6 +3,22 @@ import { ContentScriptType } from 'api/types'; joplin.plugins.register({ onStart: async function() { + await joplin.commands.register({ + name: 'testCommand', + label: 'My Test Command', + execute: async (...args) => { + alert('Got command "testCommand" with args: ' + JSON.stringify(args)); + }, + }); + + await joplin.commands.register({ + name: 'testCommandNoArgs', + label: 'My Test Command (no args)', + execute: async () => { + alert('Got command "testCommandNoArgs"'); + }, + }); + await joplin.plugins.registerContentScript( ContentScriptType.MarkdownItPlugin, 'justtesting', diff --git a/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.css b/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.css index a168fce07..dcfc4e668 100644 --- a/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.css +++ b/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.css @@ -1,4 +1,9 @@ .just-testing { - background-color: red; - color: yellow; + background-color: rgb(202, 255, 255); + color: rgb(82, 0, 78); +} + +.just-testing a { + background-color: rgb(202, 255, 255); + color: rgb(10, 0, 104); } \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.js b/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.js index a294bfb25..63520367e 100644 --- a/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.js +++ b/packages/app-cli/tests/support/plugins/content_script/src/markdownItTestPlugin.js @@ -6,7 +6,13 @@ function plugin(markdownIt, _options) { markdownIt.renderer.rules.fence = function(tokens, idx, options, env, self) { const token = tokens[idx]; if (token.info !== 'justtesting') return defaultRender(tokens, idx, options, env, self); - return `
JUST TESTING: ${token.content}
`; + return ` +
+

JUST TESTING: ${token.content}

+

Click to send "testCommand" to plugin

+

Click to send "testCommandNoArgs" to plugin

+
+ `; }; } diff --git a/packages/app-desktop/gui/NoteEditor/utils/useMessageHandler.ts b/packages/app-desktop/gui/NoteEditor/utils/useMessageHandler.ts index f305b94fa..abca8e5f8 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useMessageHandler.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useMessageHandler.ts @@ -3,6 +3,7 @@ import { FormNote } from './types'; import contextMenu from './contextMenu'; import ResourceEditWatcher from '@joplin/lib/services/ResourceEditWatcher/index'; import { _ } from '@joplin/lib/locale'; +import CommandService from '@joplin/lib/services/CommandService'; const BaseItem = require('@joplin/lib/models/BaseItem'); const BaseModel = require('@joplin/lib/BaseModel').default; const Resource = require('@joplin/lib/models/Resource.js'); @@ -90,6 +91,10 @@ export default function useMessageHandler(scrollWhenReady: any, setScrollWhenRea } } else if (msg.indexOf('#') === 0) { // This is an internal anchor, which is handled by the WebView so skip this case + } else if (msg === 'contentScriptExecuteCommand') { + const commandName = arg0.name; + const commandArgs = arg0.args || []; + void CommandService.instance().execute(commandName, ...commandArgs); } else { bridge().showErrorMessageBox(_('Unsupported link or message: %s', msg)); } diff --git a/packages/app-desktop/gui/note-viewer/index.html b/packages/app-desktop/gui/note-viewer/index.html index 5a0dbe00c..e7cd582c3 100644 --- a/packages/app-desktop/gui/note-viewer/index.html +++ b/packages/app-desktop/gui/note-viewer/index.html @@ -49,10 +49,24 @@