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
12
votes
1 answer

How to add a non editable tag to content in Quill editor

I want to add a couple of pre-built labels like
Label Text x
to the html content in the quill editor. Add such a tag should not be a problem in itself. However I don't want the user to be able to edit the text…
pravin
  • 1,106
  • 1
  • 18
  • 27
9
votes
2 answers

Is there a way to add an "Edit HTML" button to bootstrap-wysihtml5 when integrating with Rails_Admin?

The Rails_Admin wiki explains how to integrate with bootstrap-wysihtml5 which is incredibly easy. However, I'd like the wysihtml5 widget to have the "edit as html" button. Is this possible?
andy
  • 8,775
  • 13
  • 77
  • 122
9
votes
2 answers

How to disabled wysihtml5 HTML Clean Up in Editor?

How to disable HTML Clean Up while in the editor mode? I'm in a need of allowing css format & inline html in code. The idea is to disable parser and html clean up action when pasting the code and entering the Editor for editing. Thanks.
duy
  • 1,890
  • 4
  • 16
  • 20
8
votes
3 answers

Customize WYSIHTML5 Toolbar

How do you customize the toolbar in WYSIHTML5. I want to disable the font size and image insert buttons, particularly for the WYSIHTML5 version used in Bootstrap X-editable.
user2694939
  • 81
  • 1
  • 1
  • 2
7
votes
1 answer

wysihtml5 override link dialogue behaviour

I want to be able to add arbitrary text as link hrefs using wysihtml5. For example: I want to generate this link I have worked out how to do this -- here's a simplified example of what I'm doing: editor = new…
benjaminjosephw
  • 4,369
  • 3
  • 21
  • 40
7
votes
2 answers

wysihtml5: Copying text from a word document to the editor

When copying text from word to the wysihtml5 editor, the text gets messed up (both in term of formatting and in terms of additional added characters). Is there an easy fix for this? The correct behavior I am looking for would be the way Stack…
AndraD
  • 2,830
  • 6
  • 38
  • 48
6
votes
4 answers

bootstrap wysihtml5 set Value not working

I have a wysihtml box and I want to fill its value after an ajax call $("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5(); function ModificaCategoria(id) { $.ajax({ url: "Categorie.aspx/GetCategoria", …
Martina
  • 1,852
  • 8
  • 41
  • 78
6
votes
1 answer

wysihtml5 cursor jumps to wrong place on new line

When 'return' or 'enter' is hit, the cursor does not follow the actual line. Is there a solution to the problem? There are a few forks to the plugin which fixes the issue, but I am curious what the actual solution was to fix it. This is a jQuery…
Chandrew
  • 16,987
  • 4
  • 24
  • 40
6
votes
6 answers

Validation in Bootstrap wysiwyg5 editor

I am using Bootstrap wysiwyg5 editor as a part of a form. This text area happens to be a required field(should not be empty). I want to validate if the user has entered any value on to this field or not. I see that Bootstrap wysiwyg uses a Iframe…
codeMan
  • 5,730
  • 3
  • 27
  • 51
6
votes
1 answer

add custom class to wysihtml5 text editor

I'd like to be able to add a button that adds my own custom class. I don't see this in the documentation anywhere but seems like a common request. For example. Highlighting "Some Text" and pressing the button "Custom Class" will add
dardub
  • 3,166
  • 5
  • 29
  • 31
5
votes
1 answer

Wysihtml5 not working, Uncaught TypeError: $(...).wysihtml5 is not a function

This is my application.html.erb. I think I have all the proper files but it is not recognizing ".wysihtml5" function.
user3972049
5
votes
1 answer

'Range.detach' is now a no-op, as per DOM

I have been noticing this warning and error message in my console after updating Chrome to 36.0.1985.125. Warning: 'Range.detach' is now a no-op, as per DOM (http://dom.spec.whatwg.org/#dom-range-detach). Error: Discontiguous selection is not…
Chandrew
  • 16,987
  • 4
  • 24
  • 40
5
votes
1 answer

to_json on single value can't be parse back

i'm trying to implement wysihml5 in a sinatra app using Activerecord. The rich text editor works great and when i submit the form i got right html post to controller: pry:> request.params => {"title" => "title text", "content" => "bold…
Joeyjoejoe
  • 716
  • 2
  • 6
  • 18
5
votes
2 answers

Best way to process bootstrap-wysihtml5 output

Im using the bootstrap-wysihtml5 rich text editor bootstrap-wysihtml5 which basically works as expected. However, I was wondering what would be the best approach to process the generated HTML output for inclusion into the DOM tree. The issue is…
tomw
  • 98
  • 1
  • 6
1
2 3
11 12