Skip to content

How to create a spoiler tag extension for react-markdown? #860

Answered by novacrazy
novacrazy asked this question in Q&A
Discussion options

You must be logged in to vote

My solution is to move to https://github.com/Khan/simple-markdown (which actually turns out to be the same lib Discord uses)

var spoilerRule = {
    match: function(source) {
        return /^\|\|([\s\S]+?)\|\|(?!\|)/.exec(source);
    },
    parse: function(capture, parse, state) {
        return { content: parse(capture[1], state) };
    },
    react: function(node, output, state) {
        return <CustomSpoiler key={state.key}>{output(node.content, state)}</CustomSpoiler>
    },
};

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@wooorm
Comment options

@srevenant
Comment options

@ChristianMurphy
Comment options

@ChristianMurphy
Comment options

@JounQin
Comment options

JounQin Feb 14, 2025
Collaborator

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by novacrazy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants