Extension with submenu with reversed notation

I don’t fill good (yet) in development of extensions with submenu. I understand the idea presented in example with ruby, but in that case the action for menu and submenus is external and easy to point out as an action in each element of YAML array. But what in case when I want to service all submenus with the same JavaScript and additionally use reverse notation (YAML in comments of extension). Any working example would be very appreciated by me.
The need in my case is just use submenu element as parameter driving main script. F. ex. setup wiki color with different colors in submenu, but in all cases the rest of the script is exactly the same.

Hi – great question. For JavaScript it needs to be a module-based extension. Here’s an example:

// #popclip
// name: Comment
// icon: symbol:text.bubble
// language: javascript
// module: true

exports.actions = [
  {
    title: "Comment",
    code: (input) => popclip.pasteText(`<!-- ${input.text.trim()} -->`),
    submenu: [
      {
        title: "Hash Comment",
        code: (input) => popclip.pasteText(input.text.replaceAll(/^/gm, "# ")),
      },
      {
        title: "Slash Comment",
        code: (input) => popclip.pasteText(input.text.replaceAll(/^/gm, "// ")),
      },
      {
        title: "CSS Comment",
        code: (input) => popclip.pasteText(`/* ${input.text.trim()} */`),
      },
    ],
  },
];

I’ve added this example to docs.

1 Like