···85858686
87878888-
8888+ heres an image which should be on the right while this text wraps around it? i hope? make sure the image goes first tho !!!!
89899090
+46-2
rehype-custom-html.ts
···2929 }
3030}
31313232+/*
3333+ image flags go in alt text
3434+ if alt text has a pipe (|), there are flags
3535+ all words up to the first pipe are treated as flags in a space seperated list
3636+ they are added to the data tag as [data-img-flag--<name>="true"]
3737+*/
3838+3939+function image(node: Element) {
4040+ // get alt; throw error if missing; convert to string
4141+ const alt = (
4242+ node.properties.alt ??
4343+ (() => {
4444+ throw new Error("NO ALT TEXT!!!");
4545+ })()
4646+ ).toString();
4747+4848+ console.log(alt);
4949+ // match section before |
5050+ const prefixes = alt.match(/.*?(?= \|.*)/gm);
5151+ node.properties.alt = alt.match(/(?<= \| ).*/gm);
5252+ if (!prefixes) return;
5353+ const flags = prefixes[0].split(" ");
5454+ for (const flag of flags) {
5555+ console.log(flag);
5656+ node.properties[`data-img-flag--${flag}`] = true;
5757+ }
5858+ console.log(flags);
5959+}
6060+3261const plugin: Plugin<[Options], Root> = function (options) {
3362 return function (root, _) {
3434- for (const node of root.children) {
3535- if (node.type === "element")
6363+ for (let node of root.children) {
6464+ if (node.type === "element") {
3665 switch (node.tagName) {
3766 case "blockquote": {
3867 blockquote(node);
3968 break;
4069 }
7070+ case "p": {
7171+ let found = false;
7272+ for (const n of node.children) {
7373+ if (n.type === "element" && n.tagName === "img") {
7474+ node = n;
7575+ found = true;
7676+ }
7777+ }
7878+ if (!found) break;
7979+ }
8080+ case "img": {
8181+ image(node);
8282+ break;
8383+ }
4184 }
8585+ }
4286 }
4387 };
4488};