« Text Editor Source HTML 2.0.0

HTML source extension for Text Editor. This extension provides a set of key strokes to generate responses like in a typical HTML source code editor.


Strokes

Usage

Browser

<script src="./text-editor/index.min.js"></script>
<script src="./text-editor.history/index.min.js"></script>
<script src="./text-editor.key/index.min.js"></script>
<script src="./text-editor.source/index.min.js"></script>
<script src="./text-editor.source-x-m-l/index.min.js"></script>
<script src="./text-editor.source-h-t-m-l/index.min.js"></script>
<script>

  const editor = new TextEditor(document.querySelector('textarea'), {
      commands: {
          blocks: function () {
              return this.toggleElementsBlock([
                  ['h1'],
                  ['h2'],
                  ['h3'],
                  ['h4'],
                  ['h5'],
                  ['h6'],
                  ['p'],
                  false
              ]).record(), false;
          },
          bold: function () {
              return this.toggleElement(['strong']).record(), false;
          },
          code: function () {
              return this.toggleCode().record(), false;
          },
          image: function (hint, value) {
              return this.insertImage(hint, value, function () {
                  this.record();
              }), false;
          },
          italic: function () {
              return this.toggleElement(['em']).record(), false;
          },
          link: function (hint, value) {
              return this.insertLink(hint, value, function () {
                  this.record();
              }), false;
          },
          pull: function () {
              return this.pull().record(), false;
          },
          push: function () {
              return this.push().record(), false;
          },
          quote: function () {
              return this.toggleQuote().record(), false;
          },
          redo: function () {
              return this.redo(), false;
          },
          underline: function () {
              return this.toggleElement(['u']).record(), false;
          },
          undo: function () {
              return this.undo(), false;
          }
      },
      keys: {
          'Control-"': 'quote',
          'Control-Shift-"': 'quote',
          'Control-[': 'pull',
          'Control-\'': 'quote',
          'Control-]': 'push',
          'Control-b': 'bold',
          'Control-e': 'code',
          'Control-h': 'blocks',
          'Control-i': 'italic',
          'Control-l': 'link',
          'Control-o': 'image',
          'Control-u': 'underline',
          'Control-y': 'redo',
          'Control-z': 'undo'
      },
      tab: 2,
      // Be sure to put `TextEditor.SourceHTML` before `TextEditor.SourceXML`
      with: [TextEditor.History, TextEditor.Key, TextEditor.SourceHTML, TextEditor.SourceXML, TextEditor.Source]
  });

</script>

CommonJS

ECMAScript

Methods

Instance Methods

editor.insertImage(hint, value, then)

Insert an image from URL.

editor.insertImage('URL:', 'http://', function (value) {
    console.log(value);
});

editor.insertLink(hint, value, then)

Insert a link from URL.

editor.insertLink('URL:', 'http://', function (value) {
    console.log(value);
});

editor.insertElementBlock(value, mode = -1, clear = true)

editor.insertElementBlock(of, mode = -1, clear = true)

editor.peelElementBlock(of, wrap = false)

editor.toggleElementBlock(of, wrap = false)

editor.peelElementBlock(open, close, wrap = false)

editor.toggleElementBlock(open, close, wrap = false)

editor.wrapElementBlock(open, close, wrap = false)

editor.wrapElementBlock(of, wrap = false)

editor.toggleElements(of, wrap = false)

Toggle elements in the list.

editor.toggleElements([
    ['b'],
    ['strong'],
    false
]);

editor.toggleElementsBlock(of, wrap = false)

Toggle block elements in the list.

editor.toggleElementsBlock([
    ['h1'],
    ['h2'],
    ['h3'],
    ['h4'],
    ['h5'],
    ['h6'],
    ['p'],
    false
]);