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
0
votes
2 answers

drop event on textareas / WYSIHTML5 editor

Any idea how to listen to/hook drop event to the WYSIHTML5 editor? The thing I want is... I have wysihtml5 and under it images uploaded by the user(as seen in the attachment), when I drag and drop one of the imags to the wysihtml5, it inserts…
fxck
  • 4,898
  • 8
  • 56
  • 94
0
votes
1 answer

jQuery trigger not working in anchor link (other jQuery actions do)?

I'm using this editor: http://xing.github.com/wysihtml5/examples/simple.html (live demo). You can assign custom functions to events: "events": { "focus": function() { //my event } }, I added a custom button: "font-styles": function(locale,…
alexchenco
  • 53,565
  • 76
  • 241
  • 413
0
votes
2 answers

jQuery: function only works if followed by a broken function

It's exactly what it sounds like. I've got a groovy little plugin in my Rails app that rich-texts field areas. It works fine, except for the fact that two toolbars appear when there should only be one. $('#user_address').wysihtml5(); If, however, I…
t56k
  • 6,769
  • 9
  • 52
  • 115
0
votes
1 answer

how to hide wysihtml5 editor?

I need to hide and show the editor based on event. I initiate the editor. then, i try to hide using the code: $('#textare').hide(); but it doesn't work, since it as I think initiate iframe so how can I show and hide editor Update: I'm sorry forget…
assaqqaf
  • 1,575
  • 4
  • 21
  • 38
0
votes
2 answers

May I use many wysiwyg jquery selectors with textareas?

I'm using bootstrap-wysihtml5-rails in my rails app, all is working well until I attempt to use a wildcard selector. For example: Javascript $('[id*=some-textarea]').wysihtml5(); HTML