-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab879ab
commit ffd4781
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Injector, common } from "replugged"; | ||
// """imports""" | ||
const { parser } = common; | ||
|
||
import "./styles.css"; | ||
const injector = new Injector(); | ||
|
||
interface State { | ||
prevCapture: RegExpExecArray | null; | ||
|
||
// sigh. | ||
inQuote?: boolean; | ||
greentext?: boolean; | ||
} | ||
|
||
export async function start(): Promise<void> { | ||
// HACK: Ew, ew, ew, ew. Just ew. This is fucking awful. Just to make the | ||
// users happy, it is quickly and hackily done this way, but preferably I | ||
// would export a list of rules (in this case just one) that I inject into SM | ||
// using a plaintext patch. | ||
injector.after(parser, "parse", (args) => { | ||
return parser.reactParserFor({ | ||
greentext: { | ||
order: parser.defaultRules.text.order, | ||
// @ts-expect-error shut the fuck up | ||
match(text, state: State) { | ||
if (state.greentext || state.inQuote) return null; | ||
return ( | ||
/^$|\n$/.test(state.prevCapture != null ? state.prevCapture[0] : "") && | ||
/^(>.+?)(?:\n|$)/.exec(text) | ||
); | ||
}, | ||
// @ts-expect-error the types are literally wrong here what | ||
parse(capture, parse, state: State) { | ||
state.greentext = true; | ||
const content = parse(capture[0], state); | ||
delete state.greentext; | ||
return { content, type: "greentext" }; | ||
}, | ||
react(node, recurseOutput, state) { | ||
return ( | ||
<span className="replugged-greentext"> | ||
{/* @ts-expect-error SHUT UP */} | ||
{recurseOutput(node.content, state)} | ||
</span> | ||
); | ||
}, | ||
}, | ||
...parser.defaultRules, | ||
})(...args); | ||
}); | ||
} | ||
|
||
export function stop(): void { | ||
injector.uninjectAll(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "dev.alyxia.greentext", | ||
"name": "Greentext", | ||
"description": ">be me, use greentext", | ||
"author": { | ||
"name": "Alyxia", | ||
"discordID": "952185386350829688", | ||
"github": "lexisother" | ||
}, | ||
"version": "1.0.0", | ||
"updater": { | ||
"type": "store", | ||
"id": "dev.alyxia.greentext" | ||
}, | ||
"license": "Apache-2.0", | ||
"type": "replugged-plugin", | ||
"renderer": "index.tsx" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.theme-dark .replugged-greentext { | ||
color: #afc960; | ||
} | ||
.theme-light .replugged-greentext { | ||
color: #789922; | ||
} |