Table of Contents
This behavior is in active design now - information on this page will be updated/modified.

behavior: richtext

WYSIWYG editing behavior. It allows to edit HTML and/or wiki text in WYSIWYG manner.

The richtext is aimed to be used as:

The richtext uses so called flat DOM that is:

  1. no nested <div>s;
  2. <li> is a kind of <p> - can contain only text and spans;
  3. no nested tables;
  4. only two levels of spans are allowed - so called background (e.g. <a>) and foreground (<strong>, <em>, etc.) spans;
  5. there are no <font> elements inside the editor;
  6. limited support of CSS, e.g. no position attribute at all.

Screenshot of the sample below:

Screenshot

One more screenshot, "show rulers" mode:

richtext with rules

Floating image:

floating image

Elements

that have this behavior applied by default (see master style sheet):

Value

get/set_value methods (htmlayout) and value property (sciter) reflect current editing document and can be either HTML text or wiki (dokuwiki by default) format.

Editor allow images to be inserted from system clipboard so the value may contain image bits as base64 encoded chunks. Exact format will be specified later.

Attributes

that this behavior knows about:

Events

Together with the standard set of events (mouse, keyboard, focus) behavior: button generates:

Methods

Richtext supports following so called xcall() methods, see dom::element::xcall() function.

Basic operations and state indicators:

Load/Save, HTML or envelope

efined above;

Navigation:

If keepAnchor is true then this function is not changing anchor position of the selection. So this sequence moveCaretTo(line-end,false); moveCaretTo(line-end,true); will set selection on current line of text.

Edit operations and formatting:

Toolbar and tool buttons binding

The richtext allows to do all editing operations by using keyboard shortcuts (see below) but for convenience it also allows to bound tool buttons (a.k.a. toolbar) with internal so called editing registers of the editor. Tools container (e.g. toolbar) may contain elements with command attribute. Such elements reflect state of internal registers and allow to modify them by clicking on them (richtext-tools handles BUTTON_PRESS behavior event). The richtext changes :checked and :disabled attributes of the tool elements so this states can be styled appropriately.

Commands that the richtext knows about so far:

Editing commands

Spans

Blocks and indentation

Special key combinations

Formatting and text shortcuts

Lists and blockquotes

Table/cell specific:

Context Menu

By default <richtext> and <textarea>/<plaintext> are defined as this:

  richtext 
  {
    behavior:richtext;
    context-menu:url(res:behavior-richtext-menu.htm); 
    ...
  }
  texarea, plaintext 
  {
    behavior:plaintext; 
    context-menu:url(res:behavior-text-menu.htm); 
    ...
  }

context-menu:url(…) there means that context menu is located at address res:behavior-richtext-menu.htm.

Therefore if you need to provide your own version (e.g. localized) of these menus you can:

  1. Either to handle HLN/SCN_LOAD_DATA request and provide your own content when you will get request for res:behavior-richtext-menu.htm ans res:behavior-text-menu.htm or
  2. to modify styling for your element to something like this:

  richtext 
  {
    behavior:richtext;
    context-menu:selector( menu#for-richtext); 
    ...
  }

In this case you will need to declare such <menu id=“for-richtext”> element somewhere in your markup:

 <menu .context #for-richtext >
  <li command="richtext:undo"
	  style="foreground-image:url(res:edit-undo.png)"
	  >Undo<span .accesskey>Ctrl+Z</span></li>
  <hr/>
  <li command="richtext:cut" 
	  style="foreground-image:url(res:edit-cut.png)"
	  >Cut<span .accesskey>Ctrl+X</span></li>
  ...
 </menu>

Here is default content of Richtext Context Menu and Plaintext Context Menu. Note attribute command in menu items - it is used as command identifier for the behavior. Other portions of the markup can be changed but not command's.

HTML sample

Here is a sample of <richtext> and toolbar integration in HTML:

 <div .editor>
    <widget .toolbar>
      <widget .tb-button command=richtext:cut   title="Cut"><img src="res:edit-cut.png" /></widget>
      <widget .tb-button command=richtext:copy  title="Copy"><img src="res:edit-copy.png" /></widget>
      <widget .tb-button command=richtext:paste title="Paste"><img src="res:edit-paste.png" /></widget>
      <hr/>
      <widget .tb-button command=richtext:undo  title="Undo"><img src="res:edit-undo.png" /></widget>
      <widget .tb-button command=richtext:redo  title="Redo"><img src="res:edit-redo.png" /></widget>
      <hr/>      
      <widget .tb-button   command=richtext:strong  title="Strong emphasis"><b>B</b></widget>
      <widget .tb-button   command=richtext:em  title="Emphasis"><i>I</i></widget>
      <widget .tb-button   command=richtext:code  title="Code"><tt style="font-size:9px">code</tt></widget>
      <hr/>      
      <widget .tb-button   command=richtext:p  title="Paragraph"><b>P</b></widget>
      <widget .tb-button.h command=richtext:h1 title="Header 1">H<b>1</b></widget>
      <widget .tb-button.h command=richtext:h2 title="Header 2">H<b>2</b></widget>
      <widget .tb-button.h command=richtext:h3 title="Header 3">H<b>3</b></widget>
      <widget .tb-button.h command=richtext:h4 title="Header 4">H<b>4</b></widget>
      <hr/>      
      <widget .tb-button command=richtext:pre title="Block of plain text, pre"><tt>pre</tt></b></widget>
      <hr/>      
      <widget .tb-button command=richtext:li-ul title="List item, unordered list">ul</widget>
      <widget .tb-button command=richtext:li-ol title="List item, unordered list">ol</widget>
      <widget .tb-button command=richtext:indent-dec title="Increase level of list item or quote">i-</widget>
      <widget .tb-button command=richtext:indent-inc title="Decrease level of list item or un-quote">i+</widget>
   </widget>
   <richtext toolbar="widget.toolbar" >
      Hello <i>richtext</i> world!
   </richtext>
 </div>

[tbc]