Retrospring Formatter v1.1.0

This commit is contained in:
bunnybeam 2025-03-11 23:22:21 +00:00
parent fde3dfba70
commit cb4667775f
Signed by: bunnybeam
GPG key ID: 9A56D320981D30AF

View file

@ -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]<small>%[link]</small>"
description: "The format of the post. %[question] - The question. %[answer] - Your answer. %[link] - Link to the answer. %[br] - Line break. %[qb <text> /qb] - Quote block."
default: "%[qb %[question] /qb]%[br]%[answer]%[br]<small>%[link]</small>"
}
}
}
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")
})