feat(markdown): use BBCode-style [spoiler][/spoiler] tags

This commit is contained in:
plebeius
2026-03-06 20:54:11 +08:00
parent 0247a392c2
commit 91615dbf47
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ type Token =
| { type: 'crossBoardLink'; display: string; route: string } | { type: 'crossBoardLink'; display: string; route: string }
| { type: 'spoiler'; tokens: Token[] }; | { type: 'spoiler'; tokens: Token[] };
const SPOILER_REGEX = /<spoiler>([\s\S]*?)<\/spoiler>/; const SPOILER_REGEX = /\[spoiler\]([\s\S]*?)\[\/spoiler\]/;
const CROSSBOARD_REGEX = />>>\/((?:[a-zA-Z0-9]{1,10}\/(?:[a-zA-Z0-9]{46})?|[a-zA-Z0-9\-.]+(?:\/[a-zA-Z0-9]{46})?))[.,:;!?]*/; const CROSSBOARD_REGEX = />>>\/((?:[a-zA-Z0-9]{1,10}\/(?:[a-zA-Z0-9]{46})?|[a-zA-Z0-9\-.]+(?:\/[a-zA-Z0-9]{46})?))[.,:;!?]*/;
const QUOTE_LINK_REGEX = /(?<![>/\w])>>(\d+)(?![\d/])/; const QUOTE_LINK_REGEX = /(?<![>/\w])>>(\d+)(?![\d/])/;
const URL_REGEX = /https?:\/\/[^\s<\[\]]*[^\s<\[\].,;:!?\"'\)\]>]/; const URL_REGEX = /https?:\/\/[^\s<\[\]]*[^\s<\[\].,;:!?\"'\)\]>]/;
+1 -1
View File
@@ -23,7 +23,7 @@ export function getTextColorForBackground(rgb: string): string {
export function removeMarkdown(md: string): string { export function removeMarkdown(md: string): string {
return md return md
.replace(/<spoiler>(.*?)<\/spoiler>/gs, '$1') // spoiler tags - keep inner text .replace(/\[spoiler\](.*?)\[\/spoiler\]/gs, '$1') // spoiler tags - keep inner text
.replace(/\[([^\]]*?)\]\([^)]*\)/g, '$1') // [text](url) -> text .replace(/\[([^\]]*?)\]\([^)]*\)/g, '$1') // [text](url) -> text
.replace(/&nbsp;/g, ' ') // &nbsp; -> space .replace(/&nbsp;/g, ' ') // &nbsp; -> space
.replace(/^>\s*/gm, '') // greentext at line start .replace(/^>\s*/gm, '') // greentext at line start
+2 -2
View File
@@ -188,8 +188,8 @@ const FAQ = () => {
<dt id='spoiler'>Can I mark a submission as a spoiler?</dt> <dt id='spoiler'>Can I mark a submission as a spoiler?</dt>
<dd> <dd>
All boards allow you to mask plot-spoiling content. To mark your image as a spoiler, check the [x Spoiler?] box before submission. Spoilerizing text All boards allow you to mask plot-spoiling content. To mark your image as a spoiler, check the [x Spoiler?] box before submission. Spoilerizing text
makes it unreadable to others until they mouse over it. To spoilerize a comment, place {`<spoiler>`} tags around the text you wish to hide (ex. " makes it unreadable to others until they mouse over it. To spoilerize a comment, place {`[spoiler][/spoiler]`} tags around the text you wish to hide
{`<spoiler>`}SPIKE DIES!{`</spoiler>`}"). (ex. "{`[spoiler]`}SPIKE DIES!{`[/spoiler]`}").
</dd> </dd>
</dl> </dl>
</div> </div>