generated at
番号を振るPopupMenu
選択した部分に番号を振るPopupMenu



シンプルバージョン
1. ①
2. ②
3. ③
script.js
scrapbox.PopupMenu.addButton({ title: "#", onClick: text => text .split("\n") .map((line, index) => line.replace(/^(\s*)/, `$1${index + 1}. `)) .join("\n") });

空行を勢い余って選択するとうまくいかないあんも
空行を確認するのに使える?
line.trim() === ""



インデント部分を別カウント
1. ①
2. ②
1. ②1
2. ②2
3. ③
script.js.old
scrapbox.PopupMenu.addButton({ title: "#", onClick: (text) => { let indentLevels = {}; return text.split("\n") .map((line) => { let indent = line.match(/^\s*/)[0]; indentLevels[indent] = (indentLevels[indent] || 0) + 1; return line.replace(/^(\s*)/, `$1${indentLevels[indent]}. `); }) .join("\n"); }, });