番号を振るPopupMenu
選択した部分に番号を振るPopupMenu
シンプルバージョン
1. ①
2. ②
3. ③
code:script.js
scrapbox.PopupMenu.addButton({
title: "#",
onClick: text => text
.split("\n")
.map((line, index) => line.replace(/^(\s*)/, $1${index + 1}. ))
.join("\n")
});
空行を勢い余って選択するとうまくいかないあんも.icon
空行を確認するのに使える?
String.prototype.trim() - JavaScript | MDN
line.trim() === ""
インデント部分を別カウント
1. ①
2. ②
1. ②1
2. ②2
3. ③
code:script.js.old
scrapbox.PopupMenu.addButton({
title: "#",
onClick: (text) => {
let indentLevels = {};
return text.split("\n")
.map((line) => {
let indent = line.match(/^\s*/)0;
indentLevelsindent = (indentLevelsindent || 0) + 1;
return line.replace(/^(\s*)/, $1${indentLevels[indent]}. );
})
.join("\n");
},
});
/customize/箇条書きに番号を付けるUserScript