From f02da6ec65aa7ccf29b5bd9525266057b07307f4 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:02:12 -0400 Subject: [PATCH] Get rid of special image directive and support markdown image syntax --- src/components/wiki.ts | 11 ++++++++--- wiki_articles/README.md | 2 +- wiki_articles/special_members.md | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/wiki.ts b/src/components/wiki.ts index 3f65da5f..2affcd9a 100644 --- a/src/components/wiki.ts +++ b/src/components/wiki.ts @@ -4,7 +4,7 @@ import * as Discord from "discord.js"; import * as fs from "fs"; import * as path from "path"; -import { M } from "../utils.js"; +import { M, unwrap } from "../utils.js"; import { bot_spam_id, colors, resources_channel_id, rules_channel_id, stackoverflow_emote } from "../common.js"; import { BotComponent } from "../bot-component.js"; import { Wheatley } from "../wheatley.js"; @@ -41,6 +41,8 @@ type WikiField = { enum parse_state { body, field, footer, before_inline_field, done } +const image_regex = /!\[[^\]]*\]\(([^)]*)\)/; + /** * One-time use class for parsing articles. */ @@ -98,6 +100,8 @@ class ArticleParser { this.parse_directive(directive); } else if(trimmed === "---") { this.parse_directive(trimmed); + } else if(trimmed.match(image_regex)) { + this.parse_directive(trimmed); } else { this.parse_regular_line(line); } @@ -140,8 +144,9 @@ class ArticleParser { this.set_author = true; } else if(directive === "no embed") { this.no_embed = true; - } else if (directive.startsWith("image ")) { - this.image = directive.substring("image ".length).trim(); + } else if(directive.match(image_regex)) { + const match = unwrap(directive.match(image_regex))[1]; + this.image = match.trim(); } else if(directive.startsWith("alias ")) { const aliases = directive .substring("alias ".length) diff --git a/wiki_articles/README.md b/wiki_articles/README.md index 42095142..04c444ab 100644 --- a/wiki_articles/README.md +++ b/wiki_articles/README.md @@ -51,7 +51,7 @@ This is a part of the embed at the bottom, displayed with small font. ### Image ```md - +![](https://xyz.xyz/image.png) ``` Any embed can contain exactly one image. This image is displayed at the bottom of the embed, after any fields. diff --git a/wiki_articles/special_members.md b/wiki_articles/special_members.md index c64bddd2..a62e8e69 100644 --- a/wiki_articles/special_members.md +++ b/wiki_articles/special_members.md @@ -1,5 +1,5 @@ # Special Member Functions in C++ - +![](https://cdn.discordapp.com/attachments/861906541823918101/877150143089098792/b2VBV.png) Special member functions in C++, such as constructors must be handled carefully to manage resources of a class. The C++ community has agreed on three guidelines: