Action

OneNote with Tasks

Posted by agiletortoise, Last update over 4 years ago

Send current draft to OneNote with tasks converted to to-do items.

OneNote uses special HTML data-tag attributes to mark up items as to-dos. This is a simple example of how to modify Markdown HTML output to match the data-tag format required.

The action will run the draft through the Markdown engine, then replace any list items (<li> tags) with paragraph elements with the necessary to-do data tag (<p data-tag=“to-do”>), removing the surrounding ul or ol HTML tags.

This is meant as a simple example and will really only work to convert simple, single-level Markdown lists with [ ] task markers. Example input:

# Project

- [ ] Task 1
- [x] Task 2

Steps

  • script

    // convert HTML output of Markdown to OneNote data-tags
    // See Microsoft Docs on data-tags for details
    // https://docs.microsoft.com/en-us/graph/onenote-note-tags
    
    let html = draft.processTemplate("%%[[draft]]%%");
    html = html.replace(/<li>\[ \] /g, "<p data-tag=\"to-do\">");
    html = html.replace(/<li>\[x\] /g, "<p data-tag=\"to-do:completed\">");
    html = html.replace(/<\/li>/g, "</p>");
    html = html.replace(/<\/?[uo]l>/g, "\n");
    alert(html);
    draft.setTemplateTag("html", html);
  • onenote

    notebook
    Testing
    section
    Drafts
    page
    [[time]]
    template
    [[html]]
    format
    html
    writeType
    create

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.