Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textarea with a few editing options [closed]

I need a simple text editor on my site, just with the following options:
- ordered and unordered lists
- heading or bold characters
- horizontal rule

Is there any way to get the above by coding, inside an existing textarea tag

I tried with contentEditable div but there is a lot of problems there, for example return changes the format of preceding text and so on.


1 Answers

You can use ckeditor, it's very simple and customizable

https://ckeditor.com/ckeditor-5/

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CKEditor 5 – Classic editor</title>
    <script src="https://cdn.ckeditor.com/ckeditor5/11.0.1/classic/ckeditor.js"></script>
</head>
<body>
    <h1>Classic editor</h1>
    <textarea name="content" id="editor">
        &lt;p&gt;This is some sample content.&lt;/p&gt;
    </textarea>
    <script>
        ClassicEditor
            .create( document.querySelector( '#editor' ) )
            .catch( error => {
                console.error( error );
            } );
    </script>
</body>
</html>
like image 97
Ruben Sala Avatar answered Nov 02 '25 20:11

Ruben Sala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!