Skip to content

Commit

Permalink
[greentext] Add
Browse files Browse the repository at this point in the history
  • Loading branch information
lexisother committed Jul 6, 2023
1 parent ab879ab commit ffd4781
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
56 changes: 56 additions & 0 deletions plugins/greentext/index.tsx
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();
}
18 changes: 18 additions & 0 deletions plugins/greentext/manifest.json
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"
}
6 changes: 6 additions & 0 deletions plugins/greentext/styles.css
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;
}

0 comments on commit ffd4781

Please sign in to comment.