Questions tagged [wysihtml5]

wysihtml5 is an inline HTML5 editor which creates semantic code.

wysihtml5 is an open-source rich text editor based on HTML 5 technology and the progressive-enhancement approach.

It uses a sophisticated security concept and aims to generate fully valid HTML 5 markup by preventing unmaintainable tag soups and inline styles.

The Getting Started Guide explains how to integrate wysihtml5 easily into your website.

1. Include scripts

    <!-- wysihtml5 parser rules -->
    <script src="/path-to-wysihtml5/parser_rules/advanced.js"></script>
    <!-- Library -->
    <script src="/path-to-wysihtml5/dist/wysihtml5-0.3.0.min.js"></script>
  • The first script contains the html5 parser rules that are needed for wysihtml5 in order to create valid and desired markup. Either use one of the "existing parser rules sets" or create your own.
    Check the "advanced.js parser rules" for details.
  • The second script is the minified wysihtml5 library. It's located in the "dist" folder of this repository.

2. Create a textarea

    <form><textarea id="wysihtml5-textarea" placeholder="Enter your text ..." autofocus></textarea></form>
  • wysihtml5 takes a textarea and transforms it into a rich text editor. The textarea acts as a fallback for unsupported browsers (eg. IE < 8). Make sure the textarea element has an id, so we can later access it easily from javascript. The resulting rich text editor will much behave and look like the textarea since behavior (placeholder, autofocus, ...) and css styles will be copied over.

  • Please note: The textarea will always hold the editor's generated markup. Therefore wysihtml5 integrates smoothly with forms.

3. Create a toolbar

      <div id="wysihtml5-toolbar" style="display: none;">
        <a data-wysihtml5-command="bold">bold</a>
        <a data-wysihtml5-command="italic">italic</a>

        <!-- Some wysihtml5 commands require extra parameters -->
        <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a>
        <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a>
        <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a>

        <!-- Some wysihtml5 commands like 'createLink' require extra paramaters specified by the user (eg. href) -->
        <a data-wysihtml5-command="createLink">insert link</a>
        <div data-wysihtml5-dialog="createLink" style="display: none;">
          <label>
            Link:
            <input data-wysihtml5-dialog-field="href" value="http://" class="text">
          </label>
          <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
        </div>
      </div>
  • The toolbar contains the formatting options. Make sure the toolbar element has an id and has display: none.

  • Please note: wysihtml5 supports many more formatting commands. Check the "advanced demo" or find a full list of "all supported commands here".

4. Initialize wysihtml5

      <script>
      var editor = new wysihtml5.Editor("wysihtml5-textarea", { // id of textarea element
        toolbar:      "wysihtml5-toolbar", // id of toolbar element
        parserRules:  wysihtml5ParserRules // defined in parser rules set 
      });
      </script>
  • Make sure you place the <script> at the end of the document, before the </body> tag because the document must be loaded before running the script. Or, test if document is loaded (i.e. jQuery's $(document).ready()) and initialize the editor aferwards.

  • wysihtml5 supports many more "configuration options".

5. Use a set of CSS classes to style the editor's content

  • Browsers use a default style sheet to style elements, so if you use b, i, ul and li, there is already some styling visible in the editor.

  • But for the colors, we use classes like .wysiwyg-color-fuchsia, and for floats, we use .wysiwyg-float-right or -left.

  • See the "CSS of the advanced demo" (see the "whitelist of allowed classes"). You can add these classes with the "stylesheets - configuration option" (when you initialize wysihtml5, see above), i.e.

    stylesheets: ["css/reset.css", "css/editor.css"]
    
  • The stylesheets are linked from within the head of the iframe's content then.

173 questions
5
votes
1 answer

Capybara-webkit throws Can't find variable: $

I'm trying to fill a wysihmlt5 textarea with Capybara-webkit (not sure if there is another way): Capybara.default_driver = :webkit page.execute_script %Q{ $('#wysihtml5-textarea').data("wysihtml5").editor.setValue('Lorem ipsum') } But I get thsi…
alexchenco
  • 53,565
  • 76
  • 241
  • 413
5
votes
2 answers

Programmatically retrieve content from WYSIHTML5 editor

How do I programmatically retrieve content from a WYSIHTML5 editor? Suppose the editor is instantiated as this: var editor = new wysihtml5.Editor ( $(this.el).find('textarea').get(0), { toolbar: "toolbar", parserRules: …
Dalen
  • 8,856
  • 4
  • 47
  • 52
4
votes
5 answers

wysihtml5 - setting a value won't work, because 'sandbox iframe isn't loaded yet'

I'm just working on a little webservice. Therefore I am using an AJAX call and append my data to a table on my website. Here I can read and update already existing entries or write new entries. Everything works fine. I want to have the possibility…
Fabi
  • 274
  • 4
  • 15
4
votes
1 answer

How to set text box width in wysihtml5

I am trying to implement wysihtml5 in a bootstrap from But the width of the text are appears to be be small ,I tried cols attribute, but didn't work
Tachyons
  • 2,131
  • 1
  • 21
  • 35
4
votes
1 answer

Allow all attributes in bootstrap wysihtml5 editor

I want to add different custom attributes into the html view of my bootstrap-wysihtml5 editor. but they are stripped by default perserRules. So is there any simple perserRule to allow all my custom attributes? Update What I am currently doing…
sovan
  • 479
  • 6
  • 21
4
votes
0 answers

Wysihtml5 - Turn off HTML Sanitizer

I am building a page builder that is used like the WordPress page builder - it needs to not change any of the html that I program into the page (I am a programer and am using this - so that I can easily revision the page and it's changes while not…
Tyler Wall
  • 3,747
  • 7
  • 37
  • 52
4
votes
1 answer

"lock" a portion of HTML in wysiHTML5

I'm using https://github.com/xing/wysihtml5 for an editor in my code base and I'd like to "lock" portions of the code to not be editable, like so: