forked from bunnybeam/misskey-plugins
List Sort v1.0.0
This commit is contained in:
parent
3bed0b4471
commit
694e7002ed
1 changed files with 39 additions and 0 deletions
39
list-sort.ais
Normal file
39
list-sort.ais
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/// @ 0.19.0
|
||||||
|
### {
|
||||||
|
name: "List Sort"
|
||||||
|
version: "1.0.0"
|
||||||
|
author: "@bunnybeam@transfem.social"
|
||||||
|
description: "Adds a post form action that sorts lists in a note."
|
||||||
|
config: {
|
||||||
|
prefix: {
|
||||||
|
type: "string"
|
||||||
|
label: "Prefix"
|
||||||
|
description: "The prefix used to denote lines in a list. Beware of trailing whitespace!"
|
||||||
|
default: "- "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin:register_post_form_action("Sort lists", @(note, rewrite) {
|
||||||
|
let prefix = Plugin:config.prefix
|
||||||
|
let lines = note.text.split(Str:lf)
|
||||||
|
var lines_out = []
|
||||||
|
var sort_buffer = []
|
||||||
|
each let line, lines {
|
||||||
|
if line.starts_with(prefix) {
|
||||||
|
sort_buffer.push(line)
|
||||||
|
} else {
|
||||||
|
sort_buffer.sort(lt_lower)
|
||||||
|
lines_out = lines_out.concat(sort_buffer)
|
||||||
|
sort_buffer = []
|
||||||
|
lines_out.push(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort_buffer.sort(lt_lower)
|
||||||
|
lines_out = lines_out.concat(sort_buffer)
|
||||||
|
rewrite("text", lines_out.join(Str:lf))
|
||||||
|
})
|
||||||
|
|
||||||
|
@lt_lower(a, b) {
|
||||||
|
return Str:lt(a.lower(), b.lower())
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue