Saturday, September 21, 2024
Google search engine
HomeLanguagesJavascriptHow to add Summernote Editor in webpage ?

How to add Summernote Editor in webpage ?

In this article, we will know about the Summernote Editor & its usage along with will understand its implementation through the example. The Summernote EditorĀ is a free & open-source super simple WYSIWYG editor based on Bootstrap & jQuery. It is a JavaScript library that can be useful to build the WYSIWYG editors online. It is maintained under MIT license by a large community. It is easy to use & contains many customizable options. It can easily be implemented in any framework like React, Django, Angular, etc.

Ā 

Features:

  • Lightweight Rich Text Editor
  • Easy installation
  • Easy integration with any framework
  • Simple UI
  • Lots of customization available.
  • Free & Open-source
  • Interactive WYSIWYG editing

There are 2 ways to use the Summernote Editor on our web page:

  • Using the downloaded precompiled and minified versions of CSS and JavaScript files from their official site.
  • Using the available CDN links for summernote CSS & js, jQuery, and Bootstrap.

We can use either of the methods to build the static site with the text editor and the content.

Approach:

  • First, download the minified precompiled version of Summernote from the official website.
  • Extract it & place it in the current working folder.
  • Create an index.html file & declare the Bootstrap & jQuery links inside the <head> tag.
  • After completing these steps, the project structure will look like the following image.

Import the Summernote:

  • First, let us import the Bootstrap from CDNs in the index.html file. All the following codes should be placed inside the Head Tags.

<!ā€“ Include libraries(jQuery, bootstrap) ā€“>
<link href=ā€https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.cssā€ rel=ā€stylesheetā€/>
<script src=ā€https://code.jquery.com/jquery-3.5.1.min.jsā€></script>
<script src=ā€https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.jsā€></script>

  • Next import the summernote CSS and JS files.

<link href=ā€/src/summernote-0.8.18-dist/summernote-bs4.min.cssā€ rel=ā€stylesheetā€/>
<script src=ā€/src/summernote-0.8.18-dist/summernote-bs4.min.jsā€></script>

  • Now in the <body> tag, initialize the summernote editor.

<div id=ā€myeditorā€></div>

<script>
$(document).ready(function() {
    $("#myeditor").summernote({
        placeholder: "Write your content here",
        height: 200,
    });
});
</script>

Now, our Text Editor has been initialized.

Example: This example illustrates the use of the Summernote Editor to build & facilitate the editor in the web pages.

HTML




<!DOCTYPE html>
<html lang="en">
Ā Ā 
<head>
Ā Ā Ā Ā <meta charset="UTF-8" />
Ā Ā Ā Ā <meta http-equiv="X-UA-Compatible" content="IE=edge" />
Ā Ā Ā Ā <meta name="viewport"Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā content="width=device-width, initial-scale=1.0" />
Ā Ā Ā Ā <title>neveropen Editor</title>
Ā Ā Ā Ā <link href=
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā rel="stylesheet" />
Ā Ā Ā Ā <script src=
Ā Ā Ā Ā </script>
Ā Ā Ā Ā <script src=
Ā Ā Ā Ā </script>
Ā Ā Ā Ā <link rel="stylesheet"Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā href="/src/summernote-0.8.18-dist/summernote-bs4.min.css" />
Ā Ā Ā Ā <script src="/src/summernote-0.8.18-dist/summernote-bs4.min.js"></script>
Ā Ā Ā Ā <link rel="stylesheet"Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā href="/src/summernote-0.8.18-dist/summernote.css" />
Ā Ā Ā Ā <script src="/src/summernote-0.8.18-dist/summernote.js"></script>
</head>
Ā Ā 
<body>
Ā Ā Ā Ā <h1>neveropen Editor</h1>
Ā Ā Ā Ā <div id="myeditor"></div>
Ā Ā Ā Ā <button type="button"Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā class="btn btn-success"Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā onclick="showContent()"> ShowĀ 
Ā Ā Ā Ā </button>
Ā Ā 
Ā Ā Ā Ā <div id="myContent" class="container"></div>
Ā Ā 
Ā Ā Ā Ā <script>
Ā Ā Ā Ā $(document).ready(function() {
Ā Ā Ā Ā Ā Ā Ā Ā $("#myeditor").summernote({
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā placeholder: "Write your content here",
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā height: 200,
Ā Ā Ā Ā Ā Ā Ā Ā });
Ā Ā Ā Ā });
Ā Ā 
Ā Ā Ā Ā function showContent() {
Ā Ā Ā Ā Ā Ā Ā Ā document.getElementById("myContent").innerHTML =Ā 
Ā Ā Ā Ā Ā Ā Ā Ā $("#myeditor").summernote("code");
Ā Ā Ā Ā }
Ā Ā Ā Ā </script>
</body>
Ā Ā 
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Firefox
  • Microsoft Edge
  • Internet Explorer
  • Opera
  • Safari

Reference: https://summernote.org/

RELATED ARTICLES

Most Popular

Recent Comments

ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
źøˆģ²œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
źµ¬ģ›”ė™ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ˜¤ģ‚°ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ•ˆģ–‘ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė™ķƒ„ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ„œģšøģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶„ė‹¹ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ź³”ė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź³ ģ–‘ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ģ„±ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ²œķ˜øė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?