JSFiddle - React, Tailwind, and code Playground

by Kai

JavaScript

function doBold (str) {
    var re = /\*{2}([\w\s]+)\*{2}/ig;
    return str.replace(re, '<strong>$1</strong>');
}

function doItalic (str) {
    var re = /\b\*{1}([\w\s]+)\*{1}\b/igm;
    return str.replace(re, '<em>$1</em>');    
}

function doBlockquote (str) {
    var re = /^>\s+([\w\s]+)/igm;
    return str.replace(re, '<blockquote>$1</blockquote>');
}

function doStrikethrough (str) {
    var re = /\b~{3}([\w\s]+)~{3}\b/igm;
    return str.replace(re, '<strike>$1</strike>');
}

function doSuperscript (str) {
    var re = /([\w\s]+)\^([\w\s]+)$/igm;
    return str.replace(re, '$1<sup>$2</sup>');
}

function doUrl (str) {
    var re = /\[([\w\s]+)\]\((.*)\)/igm;
    return str.replace(re, '<a href="$2">$1</a>');
}

alert(doBold('**Bold** and more **bold stuff**.'));