From cb4667775f2500cce50947a70e7e6c10b5030bc3 Mon Sep 17 00:00:00 2001 From: bunnybeam Date: Tue, 11 Mar 2025 23:22:21 +0000 Subject: [PATCH] Retrospring Formatter v1.1.0 --- retrospring-formatter.ais | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/retrospring-formatter.ais b/retrospring-formatter.ais index a8076d3..051774e 100644 --- a/retrospring-formatter.ais +++ b/retrospring-formatter.ais @@ -1,28 +1,44 @@ /// @ 0.19.0 ### { name: "Retrospring Formatter" - version: "1.0.0" - author: "@bunnybeam@transfem.social" + version: "1.1.0" + author: "@bunnybeam@kitsunes.club" description: "Adds a post form action that formats a retrospring answer." config: { format: { type: "string" label: "Format" - description: "The format of the post. %[question] - The question. %[answer] - Your answer. %[link] - Link to the answer. %[br] - Line break." - default: "> %[question]%[br]%[answer]%[br]%[link]" + description: "The format of the post. %[question] - The question. %[answer] - Your answer. %[link] - Link to the answer. %[br] - Line break. %[qb /qb] - Quote block." + default: "%[qb %[question] /qb]%[br]%[answer]%[br]%[link]" } } } Plugin:register_post_form_action("Retrospring format", @(note, rewrite) { + // Split into components let link_split = note.text.split("https://") let link = `https://{link_split.pop()}` let message = link_split.join("https://") let parts = message.split(" — ") + + // Perform substitutions var output = Plugin:config.format.replace("%[br]", Str:lf) output = output.replace("%[link]", link) output = output.replace("%[answer]", parts[1]) output = output.replace("%[question]", parts[0]) + + // Format quote blocks + for Math:Infinity { + let start_index = output.index_of("%[qb ") + if start_index < 0 { + break + } + let end_index = output.index_of(" /qb]", start_index) + let content = output.slice(start_index+5, end_index) + let result = `> {content.replace(Str:lf, `{Str:lf}> `)}` + output = `{output.slice(0,start_index)}{result}{output.slice(end_index + 5, output.len)}` + } + rewrite("text", output) rewrite("cw", "retrospring") })