diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js --- a/lib/shared/markdown.js +++ b/lib/shared/markdown.js @@ -252,6 +252,26 @@ const spoilerRegex: RegExp = /^\|\|([^\n]+?)\|\|/g; +function matchSpoiler(): MatchFunction { + return (source: string, state: State) => { + if (!state.inline) { + return null; + } + return spoilerRegex.exec(source); + }; +} + +function parseSpoiler( + capture: Capture, + parse: Parser, + state: State, +): UnTypedASTNode { + const content = capture[1]; + return { + content: parse(content, state), + }; +} + export { paragraphRegex, paragraphStripTrailingNewlineRegex, @@ -272,4 +292,6 @@ matchList, parseList, matchMentions, + matchSpoiler, + parseSpoiler, };