简体   繁体   中英

How to write a simple markdown (syntax) highlighter from scratch with javascript?

I want to create a simple and fast markdown highlighter with javascript.

Input:

This is a **test bold** and __italic__ markdown. 

Output (HTML):

This is a <b>**test bold**</b> and <i>__italic__</i> markdown.

I'm not sure this answer is best practice and the fastest way:

let data = 'This is a **test bold** and __italic__ markdown.';
data = data.replace(/\*\*(.*?)\*\*/g, '<b>**$1**</b>');
data = data.replace(/__(.*?)__/g, '<i>__$1__</i>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM