Cloud Stack Ninja

I'm currently writing a userscript implementing a site's limited markdown code. I have all the functions and events working to add formatting characters to the main forum post textarea. The last thing I'm trying to do is create a function which clears all formatting from the text area as well. This is the format removal function. Sadly the replace function does nothing. My console debugging code shows that it gets to and through that part of the code, the regex replace just doesn't do anything.

function undoFormatting() {
    let pattern = /(\*{2,3}|\*{1} |_|`|=|> |(!?\[|\]\((?:.*)\))|((?:\n)\d\ )| {4})/g;
    console.log('Purging Formatting');
    let pt = document.getElementById('forum_post_message').value;
    pt.replace(pattern,' ');
    ss = se = sel = tb = te = pt = null;

I've used regexr to figure out a pattern which will match all the elements needed

Read more here:

Content Attribution

This content was originally published by gwennie-chan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: