Plugin: Context Utils - Additional context menu options and editor commands for the markdown editor

Note
This plugin was created entirely with AI tools.

Note
This plugin only supports the markdown editor (codemirror 6). The legacy editor is not supported.

Context Utils

Context Utils is a Joplin plugin that adds various options to the right-click context menu in the Markdown Editor and commands for toggling task list items, contextual copy, and fetching link titles.

Context Menu Options

  • Open Link/Send Email - Open external URLs in browser or open mailto: links in default mail client.

  • Open All Links - Opens all detected HTTP(S) links in the current text selection, in selection order.

  • Add External Link - Insert a hyperlink at the cursor

  • Add Link to Note - Insert a link to another note at the cursor

  • Copy URL/Copy Email - Copy URL to clipboard, or copy email address from mailto: link.

  • Copy Code - Copy code from inline code or code block to clipboard.

  • Copy Heading Link - Display options to copy a markdown link to the heading at the cursor (internal anchor or external note link)

  • Copy Quote - Display option to copy block quote contents without quote markers

  • Toggle Task(s) - Toggle task on selected line or Toggle all tasks in selection(s).

    • Can be assigned a keyboard shortcut (uses CmdOrCtrl+Shift+Space by default).
  • Go to Footnote - Scroll editor to defintion associated with the selected Footnote reference.

  • Go to Heading - Scroll editor to specified heading when right clicking on internal anchor link (e.g. [Test](#test))

  • Open Note as Pinned Tab - Allows you to right click a link to another joplin note and pin it to a tab (requires the Note Tabs plugin)

  • Fetch Link Title(s) - Fetches the title of a URL and updates markdown link to include the title (or converts to a markdown link if its a bare URL). Operates on the single link at the cursor, or every link in the selection.

    • Can be assigned a keyboard shortcut.
    • Note that this results in an outbound request to fetch the web page title.
    • If a linkpreview.net API key is configured in plugin settings, the plugin tries linkpreview.net first and falls back to direct page fetching if needed.
    • Custom link title rules let you derive the link text directly from the URL (no page fetch). See below. Jira links are handled by a default rule.
    • Note that Open All Links and Fetch Link Title(s) do not support reference-style links or links inside embeds.

Custom link title rules

The Custom link title rules (JSON) setting holds a JSON array of rules. When a rule's regex matches a link's URL, "Fetch Link Title" uses that rule's title template as the link text instead of fetching the page. Rules are tried in order; the first matching rule that produces a non-empty title is used. If no rule produces a title, the normal fetch behavior applies.

Each rule is an object:

Field Required Description
pattern yes Regex source tested against the full URL.
title yes Template for the link text. $1$9 insert capture groups; $& inserts the whole match.
flags no Regex flags, e.g. "i" for case-insensitive.

Example — title a helpdesk ticket link from its track= query parameter so that https://helpdesk.example.com/ticket.php?track=7QF-MZP-9KD2 becomes 7QF-MZP-9KD2:

[{ "pattern": "^https?://helpdesk\\.example\\.com/.*[?&]track=([^&#]+)", "title": "$1", "flags": "i" }]

The default value ships a rule for Jira issue links (e.g. …/browse/PROJ-123PROJ-123), you can edit or remove it.

Note
Joplin settings are a single-line field, so the value must be minified (one line) JSON. Rules use your own regular expressions, so a pathological pattern could make fetching hang — keep patterns simple and anchored.

Contextual Copy

A "Contextual Copy" command is provided that will copy the innermost copyable context at the current cursor position. For example:

  • Cursor inside block quote > copies contents of the block quote
  • Cursor inside a http(s) URL > copies link
  • Cursor inside code block or inline code > copies contents of the inline code/code block
  • Mixed scenario (inline code inside a block quote) > copies code if cursor is inside the inline code, otherwise copies the quote contents.

This can be assigned a keyboard shortcut and uses CmdOrCtrl+Shift+X by default.

Settings

  • Each context menu option can be enabled or disabled in the Plugin settings.
  • Enable/Disable toast messages.
  • Optional secure linkpreview.net API key setting for link title fetching.
  • Custom link title rules (JSON) for deriving link text from the URL (see Custom link title rules).
  • Default heading format for Contextual Copy (internal or external).

Misc Notes

  • Some of these context menu options overlap with the ones provided by the Rich Markdown plugin. Each option can be toggled on/off to avoid conflicts/duplicate menu items.

Nice plugin!

I recently asked about multi-line cursor link following for the Rich Markdown plugin:

While your plugin doesn't seem to target keyboard-only operation, would an Open All Links feature like how Fetch All Link Titles works be possible?

yeah that's straightforward to add using the existing logic to detect links in a selection for fetching link titles, this is available in v1.4.3: Release v1.4.3 · bwat47/joplin-context-utils · GitHub

Thank you for adding that useful feature so quickly. Would it be possible to prevent newlines in fetched links?

yep, this fix will be available in the next release :slight_smile:

I made it available as a pre-release here: Release v1.4.6 · bwat47/joplin-context-utils · GitHub

but be aware that the pre-release removes most of the joplin resource related context menu options (open resource, open note, copy ocr text, etc...) for better compatibility with joplin 3.6 (since joplin 3.6 now includes most of these options in its native context menu), which is why I haven't pushed another release yet

The last few versions have implemented several new features + various QoL improvements:

  • Added Copy Quote and Copy Heading link context menu options
  • Added "Contextual Copy" command that will copy the current context (link/code/quote/heading) at the cursor position (default CmdOrCtrl+Shift+X)
  • Toggle Task(s) is now a single command and can be assigned a keyboard shortcut (default CmdOrCtrl+Shift+Space)
  • Toggle Task(s) now supports multiple cursors and selections
  • Option to use linkpreview.net for fetching link titles
  • Fetch Link Title(s) is now a single command and can be assigned a keyboard shortcut (no default)
  • Fetch Link Title(s) now supports multiple selections
  • Open All Links now supports multiple selections
  • Fetch Link Title(s): Added ability to create User-defined rules for deriving link titles from URLs