Skip to content

Commit

Permalink
Get rid of special image directive and support markdown image syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Jul 31, 2023
1 parent 5ffe53b commit f02da6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion wiki_articles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This is a part of the embed at the bottom, displayed with small font.

### Image
```md
<!-- image https://xyz.xyz/image.png -->
![](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.
Expand Down
2 changes: 1 addition & 1 deletion wiki_articles/special_members.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Special Member Functions in C++
<!-- image https://cdn.discordapp.com/attachments/861906541823918101/877150143089098792/b2VBV.png -->
![](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:
Expand Down

0 comments on commit f02da6e

Please sign in to comment.