Simple, beautiful wysiwyg editor

Overview

This repo is no longer maintained. bootstrap3-wysiwyg is much better

Overview

Bootstrap-wysihtml5 is a javascript plugin that makes it easy to create simple, beautiful wysiwyg editors with the help of wysihtml5 and Twitter Bootstrap.

Examples

Quick Start

If you are using rails use the bootstrap-wysihtml5-rails gem.

gem install bootstrap-wysihtml5-rails

Otherwise, download the latest version of bootstrap-wysihtml5.

Files to reference

<link rel="stylesheet" type="text/css" href="/css/bootstrap-wysihtml5.css"></link>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"></link>
<script src="js/wysihtml5-0.3.0.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-wysihtml5.js"></script>

Usage

<textarea id="some-textarea" placeholder="Enter text ..."></textarea>
<script type="text/javascript">
	$('#some-textarea').wysihtml5();
</script>

You can get the html generated by getting the value of the text area, e.g.

$('#some-textarea').val();

Advanced

Options

An options object can be passed in to .wysihtml5() to configure the editor:

$('#some-textarea').wysihtml5({someOption: 23, ...})

Buttons

To override which buttons to show, set the appropriate flags:

$('#some-textarea').wysihtml5({
	"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
	"emphasis": true, //Italics, bold, etc. Default true
	"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
	"html": false, //Button which allows you to edit the generated HTML. Default false
	"link": true, //Button to insert a link. Default true
	"image": true, //Button to insert an image. Default true,
	"color": false //Button to change color of font  
});

Custom Templates for Toolbar Buttons

To define custom templates for buttons, you can submit a customTemplates hash with the new definitions. Each entry should be a function which expects ‘locale’ and optional ‘options’ to manage the translations.

For example, the default template used for the editHtml mode button looks like this (with size fetched from the optional ‘options’)

<li>
  <div class='btn-group'>
    <a class='btn" + size + "' data-wysihtml5-action='change_view' title='" + locale.html.edit + "'><i class='icon-pencil'></i></a>"
  </div>
</li>

You can change it to not use the pencil icon (for example) by defining the custom template like this:

var myCustomTemplates = {
  html : function(locale) {
    return "<li>" +
           "<div class='btn-group'>" +
           "<a class='btn' data-wysihtml5-action='change_view' title='" + locale.html.edit + "'>HTML</a>" +
           "</div>" +
           "</li>";
  }
}

// pass in your custom templates on init
$('#some-textarea').wysihtml5({
   customTemplates: myCustomTemplates
});

This will override only the toolbar template for html, and all others will use the default.

Stylesheets

It is possible to supply a number of stylesheets for inclusion in the editor ``:</p> <pre> $('#some-textarea').wysihtml5({ "stylesheets": ["/path/to/editor.css"] }); </pre> <h3>Events</h3> <p>Wysihtml5 exposes a <a href="https://github.com/xing/wysihtml5/wiki/Events">number of events</a>. You can hook into these events when initialising the editor:</p> <pre> $('#some-textarea').wysihtml5({ "events": { "load": function() { console.log("Loaded!"); }, "blur": function() { console.log("Blured"); } } }); </pre> <h3>Shallow copy by default, deep on request</h3> <p>Options you pass in will be added to the defaults via a shallow copy. (see <a href="http://api.jquery.com/jQuery.extend/" title="">jQuery.extend</a> for details). You can use a deep copy instead (which is probably what you want if you&#8217;re adding tags or classes to parserRules) via &#8216;deepExtend&#8217;, as in the parserRules example below.</p> <h3>Parser Rules</h3> <p>If you find the editor is stripping out tags or attributes you need, then you&#8217;ll want to extend (or replace) parserRules. This example extends the defaults to allow the <code>&lt;strong&gt;</code> and <code>&lt;em&gt;</code> tags, and the class &#8220;middle&#8221;:</p> <pre> $('#some-textarea').wysihtml5('deepExtend', { parserRules: { classes: { "middle": 1 }, tags: { strong: {}, em: {} } } }); </pre> <p>There&#8217;s quite a bit that can be done with parserRules; see <a href="https://github.com/xing/wysihtml5/blob/master/parser_rules/advanced.js">wysihtml5&#8217;s advanced parser ruleset</a> for details. bootstrap-wysihtml5&#8217;s default parserRules can be found <a href="https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/bootstrap-wysihtml5.js">in the source</a> (just search for &#8216;parserRules&#8217; in the file).</p> <h3>Defaults</h3> <p>You can change bootstrap-wysihtml5&#8217;s defaults by altering:</p> <pre> $.fn.wysihtml5.defaultOptions </pre> <p>This object has the same structure as the options object you pass in to .wysihtml5(). You can revert to the original defaults by calling:</p> <pre> $(this).wysihtml5('resetDefaults') </pre> <p>Operations on the defaults are not thread-safe; if you&#8217;re going to change the defaults, you probably want to do it only once, after you load the bootstrap-wysihtml plugin and before you start instantiating your editors.</p> <h2>The underlying wysihtml5 object</h2> <p>You can access the <a href="https://github.com/xing/wysihtml5">wysihtml5 editor object</a> like this:</p> <pre> var wysihtml5Editor = $('#some-textarea').data("wysihtml5").editor; wysihtml5Editor.composer.commands.exec("bold"); </pre> <h2>I18n</h2> <p>You can use Bootstrap-wysihtml5 in other languages. There are some translations available in the src/locales directory. You can include your desired one after the plugin and pass its key to the editor. Example:</p> <pre> &lt;script src="src/locales/bootstrap-wysihtml5.pt-BR.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $('#some-textarea').wysihtml5({locale: "pt-BR"}); &lt;/script&gt; </pre> <p>It is possible to use custom translations as well. Just add a new key to $.fn.wysihtml5.locale before calling the editor constructor.</p>

Comments
  • Internationalization Support

    Internationalization Support

    I've added a basic internationalization support to bootstrap-wysihtml5, by replacing the static string in toolbar into locale specific ones. This way, a new option "locale" can be passed to the wysihtm5() method in order to translate it.

    Example (translate to Brazilian Portuguese):

    <script src="src/locales/bootstrap-wysihtml5.pt-BR.js"></script>
    
    $('#some-textarea').wysihtml5({locale: "pt-BR"});
    

    The default is English ("en") if no locale option is given. I've added the Brazilian Portuguese translation as well. Other translations may be added in the src/locales directory.

    Please let me known if something went wrong :)

    opened by volmer 12
  • Ctrl+V removes all formatting

    Ctrl+V removes all formatting

    Chrome vRetail

    Created a Header 1, added a numbered list, added a simple list, added a Header 2 then created a new paragraph with "lorem ipsum dolor sit amet", copied that snipped and pasted it to fill the paragraph, all styling is gone on the entire textarea.

    bug 
    opened by emp 12
  • bootstrap 3 support

    bootstrap 3 support

    Limitations:

    • No pretending to have backwards-support.
    • Escape doesn't dismiss modals
    • Input on modals doesn't get focus
    • Default styling is now dark to match btn-default
    • Formatting buttons don't show whether they are active or not since I removed a.btn.wysihtml5-command-active style. The correct way to do this would be to set class='active' on the button when wysihtml5-command-active but I don't know how to do that.
    • Probably other things, but it works and doesn't look bad.

    I don't expect this PR to be merged as-is. My company is using our fork until @jhollingworth puts out a proper new build.

    opened by jspiro 11
  • WYSIHTML5 doesn't work in a bootstrap modal

    WYSIHTML5 doesn't work in a bootstrap modal

    So I've been trying to get this plugin to work with jschr's Bootstrap Modal (https://github.com/jschr) but it just doesn't want to cooperate. The files I'm calling in the header look like this:

    script src="js/vendor/bootstrap-wysihtml5/lib/js/wysihtml5-0.3.0.js"
    script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
    script src="js/vendor/bootstrap.min.js"
    script src="js/vendor/bootstrap-modal/js/bootstrap-modalmanager.js"
    script src="js/vendor/bootstrap-modal/js/bootstrap-modal.js"
    script src="js/vendor/bootstrap-wysihtml5/src/bootstrap-wysihtml5.js"

    I've tried putting the bootstrap-wysihtml5.js file before the modalmanager as well, but it made no difference.

    What's happening is that the iframe's body isn't getting the correct js passed to it (from what I can tell). As a result, the editing area is uneditable and the toolbar is able to modify and affect everything on the page (including the content in the background).

    The body tag inside of the iframe is empty and just shows this:

    body marginwidth="0" marginheight="0"

    Any help on this would be greatly appreciated.

    opened by goodbomb 11
  • Has anyone gotten capybara testing working with this?

    Has anyone gotten capybara testing working with this?

    Not really an issue with bootstrap-wysihtml5 directly, but figured I'd ask.

    I'm having trouble getting capybara to fill out the textarea, or the body inside the iframe for testing.

    Was wondering if anyone found a way to do this. Thanks!

    opened by barmstrong 11
  • Add images list to images input window

    Add images list to images input window

    First pull request ever, so go easy on me, but I added the ability to specify a JSON URL, which then populates a list of image URL's in the image input window. I think this makes it a lot easier to use in many cases, where there is a list of files elsewhere.

    opened by Asherlc 9
  • cannot read property 'Editor' of undefined.

    cannot read property 'Editor' of undefined.

    using Chrome on ubuntu 11.10 The error is thrown from line number 145 of file bootstrap-wysihtml5.js when initializing a text area with the following line.

    $('#some-text-area').wysihtml5();

    opened by ric03uec 9
  • inserting text using js

    inserting text using js

    this is more of a query than an issue. I want to insert a piece of text/html into the editor after i fetch it from the server. How can i set that value in the already existing wysihtml5 editor instance. i tried doing following

    var editor = $('#sometextarea').wysihtml5().data('wysihtml5').editor; editor.setValue('some value i want to set'); or $('#sometextarea').val('some value'); or $('#sometextarea').html('some html'); none of these seem to work. can help me out on this. thanks

    opened by ric03uec 8
  • Set tabindex to -1 for toolbar buttons

    Set tabindex to -1 for toolbar buttons

    Hi and thanks for the very nice integration of wysihtml5 and bootstrap.

    I just noticed that the default toolbar buttons appear in the regular tab order when navigating a wysihtml5 enriched form. I suggest setting tabindex="-1" for all toolbar buttons so that they are skipped from tab order instead.

    Thanks, Carsten

    opened by cblock 7
  • multiple editable sections

    multiple editable sections

    Hello, first of all, thank you for sharing your work with us but damn, give us some documentation next time, it took me almost 2 hours to figure out how to retrieve the modified data from the "textarea" and sure it could be done easier than I did.

    <section id="useless" class="editable-section">
        You can use the following commit from hinrik to make tags work properly.
        https://github.com/hinrik/bootstrap-wysihtml5/commit/d9c43dedf7be76a4e7fd3a072d573aa4c130e63d
    </section>
    <section id="useless" class="editable-section">
        &nbsp;
    </section>
    

    And here goes the implementation, it sucks but works:

    $(function() {
    
        $('.editable-section').each(function(index) {
            $(this).wrapInner('<div class="editable" />');
            //$(this).children("div.editable").load("load.php", {id: 'something'});
            $(this).append('<a id="edit-section" href="#"><i class="icon-edit"></i> Edit</a>');
        });
    
        $("a#edit-section").live("click", function(){
            $("#save-section").click();     //save and remove other active editors so we can create a new one
            $(this).before('<textarea id="editable"></textarea>');
            $(this).prev().html($(this).prev().prev().html());
            $(this).prev().prev().hide();
            $(this).prev().show();
            $(this).prev().wysihtml5();
            $(this).parent().append('<a id="save-section" href="#"><i class="icon-share"></i> Save</a>');
            $(this).hide();
        });
    
        $("a#save-section").live("click", function(){
            $(this).parent().children("div.editable").html($('#editable').val());    //fixed
            $(this).parent().children("div.editable").show();
            var content = $('#editable').val();    //fixed
            $(this).parent().find("iframe.wysihtml5-sandbox").contents().find("html").remove(); //remove iframe html
            $("#editable-wysihtml5-toolbar").remove();
            $(this).parent().find("iframe.wysihtml5-sandbox").prev().remove();
            $(this).parent().find("iframe.wysihtml5-sandbox").remove(); //remove iframe
            $(this).parent().children("#editable").remove();    //remove textarea
            $().remove(wysihtml5);
            $(this).prev().show();      //show edit button
            $(this).remove();   //remove save button
    
            //finally, update server content
            //$.post("save.php", { id: 'something', html: content } );
        });
    
    });
    

    Have a good day.

    bug 
    opened by Theadd 7
  • "color": true, but the toolbar has no colour button

    i initialized as follows:

    $('#test').wysihtml5({
    "font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
    "emphasis": true, //Italics, bold, etc. Default true
    "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
    "html": false, //Button which allows you to edit the generated HTML. Default false
    "link": false, //Button to insert a link. Default true
    "image": false, //Button to insert an image. Default true,
    "color": true //Button to change color of font  
    });
    

    The colour button does not appear. Why is that?

    opened by geekyme 6
  • Regular Expression DoS vulnerability

    Regular Expression DoS vulnerability

    We are working on the ReDoS problem and detected 2 vulnerable regex(es) from your repository.

    1: :((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))? in bootstrap-wysihtml5/lib/js/jquery-1.7.2.min.js 2: ((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*) in bootstrap-wysihtml5/lib/js/jquery-1.7.2.min.js

    Please try the following:

    var pattern = ":((?:[\\w\\u00c0-\\uFFFF\\-]|\\\\.)+)(?:\\((['\"]?)((?:\\([^\\)]+\\)|[^\\(\\)]*)+)\\2\\))?";
    var input = ":\\\b(\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
    var re = new RegExp(pattern);
    var matched = input.match(re);
    
    var pattern = "((?:\\((?:\\([^()]+\\)|[^()]+)+\\)|\\[(?:\\[[^\\[\\]]*\\]|['\"][^'\"]*['\"]|[^\\[\\]'\"]+)+\\]|\\\\.|[^ >+~,(\\[\\\\]+)+|[>+~])(\\s*,\\s*)?((?:.|\\r|\\n)*)";
    var input = "[\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
    var re = new RegExp(pattern);
    var matched = input.match(re);
    

    We didn’t create a pull request because we're not sure if these cases are possible to take place in your program, we also do not understand the functionality of these regexes as you do. Thank you for your understanding.

    opened by linci8210 0
  • how to remove h1 only from the font-styles drop menu

    how to remove h1 only from the font-styles drop menu

    Is there an option to hide/show sub menu items. I want for example to hide h1 (in addition to insert image). I used the following working workaround. Is there a natural option for that? thank you:

    <script>
    if(jQuery().wysihtml5){
    $(".wysihtml5").wysihtml5( {"image": false});
    $('a[data-wysihtml5-command-value="h1"]').hide();
    }
    </script>
    
    opened by shadinamrouti 0
  • bootstrap-wysihtml5 Not showing moodle after fixing focus blank

    bootstrap-wysihtml5 Not showing moodle after fixing focus blank

    Dear,

    Can anyone help em with this plugin.

    Once i fixed the focus blank. Now modal is not showing, only black screen comes.

    I will really appriciate.

    Regards, Ankit

    opened by ankitbnl406 0
  • set different heading styles in same line

    set different heading styles in same line

    code working properly and I can change heading style for any line . my issue is that I can't change header in the same line . each line only can get one heading style.

    style1

    style2

    but i can't write both in the same line . i

    is there any solution for this issue?

    opened by AhmedEmadAhmed 0
  • Error: Failed to execute focus - on chrome v64

    Error: Failed to execute focus - on chrome v64

    Hello, We have a bug with chrome browser v64.0 when we click on buttons "insert link" or "insert image" : bootstrap-wysihtml5.min.js Uncaught TypeError: Failed to execute 'focus' on 'HTMLElement': parameter 1 ('options') is not an object.

    capture du 2018-02-14 16-22-38 capture du 2018-02-14 16-24-14

    To fix temporarily this, we had to make the following changes at lines 279 and 341

    if (!activeButton) {
        self.editor.currentView.element.focus();    // instead of ...element.focus(false);
        caretBookmark = self.editor.composer.selection.getBookmark();
    

    Can you do the necessary to fix this bug.

    thank you

    mchabou

    opened by mchabou 3
Super simple WYSIWYG editor

Summernote Super simple WYSIWYG Editor. Summernote Summernote is a JavaScript library that helps you create WYSIWYG editors online. Home page: https:/

Summernote 11k Jan 7, 2023
The next generation Javascript WYSIWYG HTML Editor.

Froala Editor V3 Froala WYSIWYG HTML Editor is one of the most powerful JavaScript rich text editors ever. Slim - only add the plugins that you need (

Froala 5k Jan 1, 2023
Quill is a modern WYSIWYG editor built for compatibility and extensibility.

Note: This branch and README covers the upcoming 2.0 release. View 1.x docs here. Quill Rich Text Editor Quickstart • Documentation • Development • Co

Quill 34.3k Jan 2, 2023
Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.

If you would be interested in helping to maintain one of the most successful WYSIWYG text editors on github, let us know! (See issue #1503) MediumEdit

yabwe 15.7k Jan 4, 2023
A lightweight and amazing WYSIWYG JavaScript editor - 20kB only (8kB gzip)

Supporting Trumbowyg Trumbowyg is an MIT-licensed open source project and completely free to use. However, the amount of effort needed to maintain and

Alexandre Demode 3.8k Jan 7, 2023
Raptor, an HTML5 WYSIWYG content editor!

Raptor Editor Raptor Editor is a user-focused extensible WYSIWYG website content editor - check out the Demo. It is designed to be user and developer

PANmedia 533 Sep 24, 2022
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.

TOAST UI Editor v3 major update planning ?? ?? ?? TOAST UI Editor is planning a v3 major update for 2021. You can see our detail RoadMap here! GFM Mar

NHN 15.5k Jan 3, 2023
A powerful WYSIWYG rich text web editor by pure javascript

KothingEditor A powerful WYSIWYG rich text web editor by pure javascript Demo : kothing.github.io/editor The KothingEditor is a lightweight, flexible,

Kothing 34 Dec 25, 2022
The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.

CKEditor 4 - Smart WYSIWYG HTML editor A highly configurable WYSIWYG HTML editor with hundreds of features, from creating rich text content with capti

CKEditor Ecosystem 5.7k Dec 27, 2022
An Easy and Fast WYSIWYG Editor

Simditor Simditor is a browser-based WYSIWYG text editor. It is used by Tower -- a popular project management web application. Supported Browsers: IE1

彩程设计 5k Jan 3, 2023
Pure javascript based WYSIWYG html editor, with no dependencies.

SunEditor Pure javscript based WYSIWYG web editor, with no dependencies Demo : suneditor.com The Suneditor is a lightweight, flexible, customizable WY

Yi JiHong 1.1k Jan 2, 2023
WYSIWYG editor developed as jQuery plugin

RichText WYSIWYG editor developed as jQuery plugin. Requirements jQuery (v.3+, v.3.2+ recommended) FontAwesome (v.4.7.0 / v.5+) src/jquery.richtext.mi

Bob 95 Dec 30, 2022
A lightweight HTML and BBCode WYSIWYG editor

SCEditor v3.1.1 A lightweight WYSIWYG BBCode and XHTML editor. For more information visit sceditor.com Usage Include the SCEditor JavaScript: <link re

Sam 566 Dec 23, 2022
A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.

SimpleMDE - Markdown Editor A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allo

Sparksuite 9.3k Jan 4, 2023
A JS library for building WYSIWYG editors for HTML content.

For information on the ContentTools 2.x roadmap please view the: Roadmap repo ContentTools A JS library for building WYSIWYG editors for HTML content.

getme 3.9k Jan 8, 2023
A toolkit for building WYSIWYG editors with Mobiledoc

Mobiledoc Kit Mobiledoc Kit is a framework-agnostic library for building WYSIWYG editors supporting rich content via cards. Libraries This repository

Bustle 1.5k Jan 3, 2023
A markdown editor. http://lab.lepture.com/editor/

Editor A markdown editor you really want. Sponsors Editor is sponsored by Typlog. Overview Editor is not a WYSIWYG editor, it is a plain text markdown

Hsiaoming Yang 2.8k Dec 19, 2022
Override the rich text editor in Strapi admin with ToastUI Editor.

strapi-plugin-wysiwyg-tui-editor ⚠️ This is a strapi v4 plugin which does not support any earlier version! A Strapi plugin to replace the default rich

Zhuo Chen 12 Dec 23, 2022
A chrome extension which helps change ace editor to monaco editor in web pages, supporting all features including autocompletes.

Monaco-It Monaco-It is a chrome extension turning Ace Editor into Monaco Editor, supporting all features including autocompletes. 一些中文说明 Supported Lan

null 3 May 17, 2022