james james - 1 month ago 8
HTML Question

How to create an input field where you can type naturally, and then it translates it into HTML?

Not entirely sure how to ask this question so sorry about that... any pointers on where to look is good.

I'm trying to have a

textarea
input field just like when you post a new StackOverflow question. You can have line spaces, you can bold text, you can insert link etc.

However, when you push some kind of button, all of that gets translated into a long HTML string (e.g., spaces become
<p>
or
<br>
, bold becomes
<strong>
, link becomes
<a>
). Is there a way to do this with some kind of JS plug in?

Answer

What you describe is a What You See Is What You Get (WYSIWYG) editor.

Google "WYSIWYG editor library"

Examples:

https://prosemirror.net/

https://www.tinymce.com/