mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Don't remove hashtags if post is only hashtags
This commit is contained in:
parent
36530e5db4
commit
21875a8e83
@ -86,6 +86,7 @@ function structure(text) {
|
|||||||
* Edit a structure in-place to remove trailing hashtags and separator characters.
|
* Edit a structure in-place to remove trailing hashtags and separator characters.
|
||||||
*/
|
*/
|
||||||
function removeTrailingHashtags(structured) {
|
function removeTrailingHashtags(structured) {
|
||||||
|
let original = structured.slice()
|
||||||
let hasHashtags = structured.some(part => part.type === "hashtag")
|
let hasHashtags = structured.some(part => part.type === "hashtag")
|
||||||
let seenHashtags = false
|
let seenHashtags = false
|
||||||
|
|
||||||
@ -111,6 +112,7 @@ function removeTrailingHashtags(structured) {
|
|||||||
|
|
||||||
while (shouldRemoveLastPart()) {
|
while (shouldRemoveLastPart()) {
|
||||||
structured.pop()
|
structured.pop()
|
||||||
|
if (structured.length === 0) return original
|
||||||
}
|
}
|
||||||
|
|
||||||
return structured
|
return structured
|
||||||
|
@ -240,5 +240,25 @@ tap.test("remove trailing hashtags", childTest => {
|
|||||||
"chongquing china"
|
"chongquing china"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
childTest.same(
|
||||||
|
removeTrailingHashtags(structure("#justice #onlyhashtags")),
|
||||||
|
[
|
||||||
|
{type: "text", text: ""},
|
||||||
|
{type: "hashtag", text: "#justice", hashtag: "justice"},
|
||||||
|
{type: "text", text: " "},
|
||||||
|
{type: "hashtag", text: "#onlyhashtags", hashtag: "onlyhashtags"},
|
||||||
|
{type: "text", text: ""}
|
||||||
|
],
|
||||||
|
"only hashtags"
|
||||||
|
)
|
||||||
|
|
||||||
|
childTest.same(
|
||||||
|
removeTrailingHashtags(structure("")),
|
||||||
|
[
|
||||||
|
{type: "text", text: ""}
|
||||||
|
],
|
||||||
|
"no content"
|
||||||
|
)
|
||||||
|
|
||||||
childTest.end()
|
childTest.end()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user