diy-markdown

node v14.20.1
version: 1.0.0
endpointsharetweet
const render_markdown = (input, features) => { if (features.bold) { input = input.replace(/\*\*\S.*?\S\*\*/g, match => { return match.replace(/^\*\*/,'<b>').replace(/\*\*$/,'</b>') }) } if (features.italic) { input = input.replace(/\*\S.*?\S\*/g, match => { return match.replace(/^\*/,'<i>').replace(/\*$/,'</i>') }) } return input }
let test_input = "*hello* **there**"
let test_features = {bold: true, italic: true}
render_markdown(test_input, test_features)
let test2_input = "***hello** there*"
render_markdown(test2_input, test_features)
const render_markdown2 = (input, features) => { console.debug(input) if (features.bold) { input = input.replace(/\*\*\S.*?\S\*\*/g, match => { return match.replace(/^\*\*/,'<b>').replace(/\*\*$/,'</b>') }) } if (features.italic) { input = input.replace(/\*\S.*?\S\*/g, match => { return match.replace(/^\*/,'<i>').replace(/\*$/,'</i>') }) } if (features.h1) { input = input.replace(/^\#.+$/gm, match => { return match.replace(/^#/, '<h1>') + '</h1>' }) } return input }
let test3_input = "#Test\n **string**"
render_markdown2(test3_input, {h1: true, ...test_features})
Loading…

no comments

    sign in to comment