forked from bunnybeam/misskey-plugins
Retrospring Formatter v1.1.0
This commit is contained in:
parent
fde3dfba70
commit
cb4667775f
1 changed files with 20 additions and 4 deletions
|
@ -1,28 +1,44 @@
|
||||||
/// @ 0.19.0
|
/// @ 0.19.0
|
||||||
### {
|
### {
|
||||||
name: "Retrospring Formatter"
|
name: "Retrospring Formatter"
|
||||||
version: "1.0.0"
|
version: "1.1.0"
|
||||||
author: "@bunnybeam@transfem.social"
|
author: "@bunnybeam@kitsunes.club"
|
||||||
description: "Adds a post form action that formats a retrospring answer."
|
description: "Adds a post form action that formats a retrospring answer."
|
||||||
config: {
|
config: {
|
||||||
format: {
|
format: {
|
||||||
type: "string"
|
type: "string"
|
||||||
label: "Format"
|
label: "Format"
|
||||||
description: "The format of the post. %[question] - The question. %[answer] - Your answer. %[link] - Link to the answer. %[br] - Line break."
|
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: "> %[question]%[br]%[answer]%[br]<small>%[link]</small>"
|
default: "%[qb %[question] /qb]%[br]%[answer]%[br]<small>%[link]</small>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin:register_post_form_action("Retrospring format", @(note, rewrite) {
|
Plugin:register_post_form_action("Retrospring format", @(note, rewrite) {
|
||||||
|
// Split into components
|
||||||
let link_split = note.text.split("https://")
|
let link_split = note.text.split("https://")
|
||||||
let link = `https://{link_split.pop()}`
|
let link = `https://{link_split.pop()}`
|
||||||
let message = link_split.join("https://")
|
let message = link_split.join("https://")
|
||||||
let parts = message.split(" — ")
|
let parts = message.split(" — ")
|
||||||
|
|
||||||
|
// Perform substitutions
|
||||||
var output = Plugin:config.format.replace("%[br]", Str:lf)
|
var output = Plugin:config.format.replace("%[br]", Str:lf)
|
||||||
output = output.replace("%[link]", link)
|
output = output.replace("%[link]", link)
|
||||||
output = output.replace("%[answer]", parts[1])
|
output = output.replace("%[answer]", parts[1])
|
||||||
output = output.replace("%[question]", parts[0])
|
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("text", output)
|
||||||
rewrite("cw", "retrospring")
|
rewrite("cw", "retrospring")
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue