scrapbox-tl-dr-processor
サムネイル画像は関係なし。
index.jsexport class ScrapboxTLDRProcessor {
async process({text}) {
const lines = text.split("\n");
const tlDRLines = lines.flatMap(
(line) => [...line.matchAll(/^(\s+)\?\s(.+)/g)]
).map(indentedHelpMatch => {
const helpLine = indentedHelpMatch[2];
const excludedWords = [...helpLine.matchAll(/\((.*?)\)/g)].flatMap(
groupMatch => groupMatch[1].split("|").flatMap(
word => word.startsWith(":") ? [`|${word}`, word] : []
)
);
return `${indentedHelpMatch[1]}${
[...excludedWords, "(", ")", "[", "]"].reduce(
(helpLine, excludedWord) => helpLine.replaceAll(excludedWord, ""),
helpLine)
.replaceAll("|", ", ")
}`;
});
return {
text: [
...lines,
...tlDRLines.length ? [
"",
"",
"(Targets)",
...tlDRLines,
""
] : [],
].join("\n")
};
}
}
? A
?B
? この(ページ|記事|:書き記し)はテストである
? つまりこの[ページ]にたどり着けた人はすごい