Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PLUGIN_SECTIONID env variable #1519

Closed
cspotcode opened this issue Aug 1, 2024 · 6 comments · Fixed by #1537
Closed

Add PLUGIN_SECTIONID env variable #1519

cspotcode opened this issue Aug 1, 2024 · 6 comments · Fixed by #1537
Assignees
Labels
feature-request New feature or request released Available in a released installer

Comments

@cspotcode
Copy link

How can I help you?

Today I hit a situation that I thought would be the perfect use-case for a plugin. Unfortunately, I hit some limitations of the current plugin implementation. This is understandable because it's experimental, and trying to support all possible use-cases is surely not a reasonable goal. However, I thought I'd share my use-case in case it inspires additional plugin features.

Use-case

Bind a hotkey to copy a markdown-formatted link to the current page or paragraph, for pasting into other apps which don't auto-detect that onenote: is a clickable link:

[Page Title Here](onenote:https://d.docs.live.net/restoftheurlhere)

Details

I use a to-do app that supports markdown hyperlinks. It doesn't automatically render onenote: links, but if I wrap them up in markdown [label](url) syntax, they render correctly. This lets me create ToDos with clickable links to associated OneNote pages.

Another benefit of markdown syntax: I can embed the page's title, which is good because the ToDo app has no way of fetching the URL's title from the web.

Plugin limitations

Unfortunately, when I tried to implement this as a plugin, I hit a couple issues.

  1. It doesn't seem possible to run plugins by name from the command palette. Ideally I hit Ctrl+Shift+P, type "plug mark" and see "Run Plugin: Copy Markdown Link," hit enter.
  2. Cannot construct the URL without access to section and page IDs. As far as I can tell, I can't get those from the page's XML.
@stevencohn
Copy link
Owner

The page ID should be an attribute of the top level Page element, attribute name "ID".

For the section ID, here's a proposed solution: There are a number of PLUGIN env variables your plugin can use, see the bottom of this OneMore Wiki page. It would be quite easy to add a PLUGIN_SECTIONID env variable when you run a page-scoped plugin.

@stevencohn stevencohn added the feature-request New feature or request label Aug 1, 2024
@cspotcode
Copy link
Author

cspotcode commented Aug 5, 2024

Environment variables would be great, yeah.


I came across another use-case: modifying highlighted text, or otherwise accessing the caret position.

With this, I could bind hotkeys to create linked tasks in my chosen ToDo app. (my Outlook is broken so I can't use the sync w/MS ToDo)

I could highlight a line of text, hit a hotkey, and my plugin creates a ToDo task from the highlighted text, creating a bidirectional link between the ToDo and the text.

If I limit myself to focusing on a page's title, then I can setup a link between title and ToDo, since that doesn't require knowing caret position or selection.

EDIT nevermind, plugins do get the current selection! https://onemoreaddin.com/developers/TechNote%20-%20Editing%20Text.htm

@stevencohn stevencohn changed the title Plugin use-cases Add PLUGIN_SECTIONID env variable Aug 5, 2024
@jasonjac2
Copy link

Could you add the Page ID to the environment variables as well, then for a lot of plugins, you might not need to parse the page at all?

stevencohn added a commit that referenced this issue Aug 14, 2024
@stevencohn stevencohn self-assigned this Aug 14, 2024
@stevencohn stevencohn linked a pull request Aug 14, 2024 that will close this issue
@stevencohn stevencohn added the next-release Addressed but not yet released label Aug 14, 2024
@stevencohn
Copy link
Owner

Environment variables will include

• PLUGIN_ASCHILD - set to true when the Create as child option is checked
• PLUGIN_CREATE - set to true when the Create as new page option is checked
• PLUGIN_PAGENAME - specifies the name of the page to create or update
• PLUGIN_SOURCE_PAGEID - the OneNote ID of the source page
• PLUGIN_SOURCE_SECTIONID - the OneNote ID of the source page's section
• PLUGIN_SOURCE_NOTEBOOKID - the OneNote ID of the source page's notebook
• PLUGIN_SOURCE_PAGENAME - the title of the source page
• PLUGIN_SOURCE_PAGEPATH - the hierarchy path of the source page, including notebook, section, and page name
• PLUGIN_SOURCE_PAGEURL - the OneNote URL of the source page
• PLUGIN_SKIPLOCK - set to true when the Skip locked sections option is checked

@jasonjac2
Copy link

Section Groups - do they change the hierarchy of the path?
I'll have to read up on skipLock.
All brilliant - thanks.

@stevencohn
Copy link
Owner

stevencohn commented Aug 14, 2024

Yes, section groups are part of the path.

Regarding skipLock, if a section is password-protected, the Plugin has no means to ask for a password and unlock it. So either it attempts to open it and will fail, or you specify Skip and it won't even try.

@stevencohn stevencohn added released Available in a released installer and removed next-release Addressed but not yet released labels Aug 25, 2024
weissm pushed a commit to weissm/OneMore that referenced this issue Sep 7, 2024
weissm pushed a commit to weissm/OneMore that referenced this issue Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request released Available in a released installer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants