All Projects → GitbookIO → Slate Edit Code

GitbookIO / Slate Edit Code

Licence: apache-2.0
A Slate plugin for code block editing

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Slate Edit Code

Canner Slate Editor
📝Rich Text / WYSIWYG Editor built for Modularity and Extensibility.
Stars: ✭ 1,071 (+2334.09%)
Mutual labels:  slate, rich-text-editor, wysiwyg
Re Editor
一个开箱即用的React富文本编辑器 🚀re-editor
Stars: ✭ 367 (+734.09%)
Mutual labels:  slate, rich-text-editor, wysiwyg
Slate Plugins
🔌 Next-gen slate plugins
Stars: ✭ 399 (+806.82%)
Mutual labels:  slate, rich-text-editor, wysiwyg
Slate Edit Table
Slate plugin for table edition
Stars: ✭ 97 (+120.45%)
Mutual labels:  slate, rich-text-editor, wysiwyg
Awesome Web Editor
🔨 Open source WEB editor summary
Stars: ✭ 306 (+595.45%)
Mutual labels:  rich-text-editor, wysiwyg
Angular Froala Wysiwyg
Angular 4, 5, 6, 7, 8 and 9 plugin for Froala WYSIWYG HTML Rich Text Editor.
Stars: ✭ 696 (+1481.82%)
Mutual labels:  rich-text-editor, wysiwyg
Braft Editor
美观易用的React富文本编辑器,基于draft-js开发
Stars: ✭ 4,310 (+9695.45%)
Mutual labels:  rich-text-editor, wysiwyg
Jodit
Jodit - Best WYSIWYG Editor for You
Stars: ✭ 947 (+2052.27%)
Mutual labels:  rich-text-editor, wysiwyg
Trix
A rich text editor for everyday writing
Stars: ✭ 16,546 (+37504.55%)
Mutual labels:  rich-text-editor, wysiwyg
Angular Editor
A simple native WYSIWYG editor component for Angular 6 -10+
Stars: ✭ 428 (+872.73%)
Mutual labels:  rich-text-editor, wysiwyg
Awesome Medium Editor
Medium.com WYSIWYG editor clone, with RTL support.
Stars: ✭ 12 (-72.73%)
Mutual labels:  rich-text-editor, wysiwyg
Uncolored
(Un)colored — Next generation desktop rich content editor that saves documents with themes. HTML & Markdown compatible. For Windows, OS X & Linux. — http://n457.github.io/Uncolored/
Stars: ✭ 733 (+1565.91%)
Mutual labels:  rich-text-editor, wysiwyg
Trumbowyg
A lightweight and amazing WYSIWYG JavaScript editor under 10kB
Stars: ✭ 3,664 (+8227.27%)
Mutual labels:  rich-text-editor, wysiwyg
Wysiwyg.js
wysiwyg contenteditable editor (minified+compression: 6kb)
Stars: ✭ 520 (+1081.82%)
Mutual labels:  rich-text-editor, wysiwyg
Wysiwyg Editor
The next generation Javascript WYSIWYG HTML Editor.
Stars: ✭ 4,756 (+10709.09%)
Mutual labels:  rich-text-editor, wysiwyg
Simditor
An Easy and Fast WYSIWYG Editor
Stars: ✭ 4,926 (+11095.45%)
Mutual labels:  rich-text-editor, wysiwyg
Element Tiptap
🌸A modern WYSIWYG rich-text editor using tiptap and Element UI for Vue.js
Stars: ✭ 481 (+993.18%)
Mutual labels:  rich-text-editor, wysiwyg
Megadraft
Megadraft is a Rich Text editor built on top of Facebook's Draft.JS featuring a nice default base of components and extensibility
Stars: ✭ 982 (+2131.82%)
Mutual labels:  rich-text-editor, wysiwyg
Django Front
Django-front is a front-end editing Django application
Stars: ✭ 257 (+484.09%)
Mutual labels:  rich-text-editor, wysiwyg
Text
📑 Collaborative document editing using Markdown
Stars: ✭ 282 (+540.91%)
Mutual labels:  rich-text-editor, wysiwyg

⚠️ This repository is archived and has moved to GitBook's fork of ianstormtaylor/slate. Previous versions are still available on NPM All the versions using GitBook's fork of slate are now published under the @gitbook NPM scope. To learn more about why we forked Slate, read our manifest

slate-edit-code

NPM version Linux Build Status

A Slate plugin to handle code block editing.

Install

npm install slate-edit-code

Features

  • Pressing Enter insert a new line starting with the right indentation
  • Pressing Tab insert the right indentation if selection is collapsed or indent all lines in selection
  • Pressing Delete remove the indentation before cursor if possible
  • Pressing Mod+Enter exits the code block
  • Pressing Mod+A selects all the text in the block

Mod means Ctrl on Windows/Linux and Command on Mac.

Structure

This plugin uses the following structure for code blocks:

<code_block>
  <code_line>A code block is made of</code_line>
  <code_line>several code lines</code_line>
</code_block>

Texts inside code_blocks that contain newlines \n are automatically split into the appropriate number of code_lines.

Simple Usage

import EditCode from 'slate-edit-code'

const plugins = [
  EditCode()
]

Options arguments

  • containerType = 'code_block' : string — The type of the code containers
  • lineType = 'code_line' : string — The type of the code lines
  • exitBlockType = 'paragraph' : null | stringMod+Enter will exit the code container, into the given block type. Backspace at start of an empty code container will convert it to the given block type. Pass null to disable this behavior.
  • onExit: (Change) => void | Change — Change to do when the user hits Mod+Enter. Defaults to exiting the code block, into a new exitBlockType block.
  • selectAll = true : boolean — True to select all code inside a code container on Mod+A
  • allowMarks = false : boolean — False disallow marks in code blocks by normalizing them away.
  • getIndent: (Value) => string — Returns the indent unit as a string. The current value is passed as context.

Suppressing onKeyDown behavior

Some behavior implemented by this plugins have no corresponding option. While there is an option selectAll to disable the behavior on Mod+A, If you would like to fine tune these behavior, you can always redefine the exported onKeyDown function.

The following example disable all indent behavior

import EditCode from 'slate-edit-code'

const options = { ... };

const basePlugin = EditCode(options);

const customPlugin = {
  ...basePlugin,
  onKeyDown(event, change, editor) {
    if (event.key === 'Tab') {
      // Bypass the original plugin behavior on `Tab`
      return;
    } else {
      return basePlugin.onKeyDown(event, change, editor);
    }
  }
}

// Use customPlugin later on

Utilities and Changes

slate-edit-code exports utilities, accessible like so:

const plugin = EditCode()

// Access exported utilities there
plugin.utils

utils.deserializeCode

plugin.utils.deserializeCode(text: String) => Block

Split a text string into lines, and deserialize them to a code_container Block, with one children code_line Block per line.

changes.toggleCodeBlock

plugin.changes.toggleCodeBlock(change: Change, type: String) => Change

Toggle a block into a code block or a normal block (defined by type).

changes.wrapCodeBlockByKey

plugin.changes.wrapCodeBlockByKey(change: Change, key: String) => Change

Convert a block (paragraph, etc) into a code block.

changes.wrapCodeBlock

plugin.changes.wrapCodeBlock(change: Change) => Change

Convert current block (paragraph, etc) into a code block.

changes.unwrapCodeBlockByKey

plugin.changes.unwrapCodeBlockByKey(change: Change, key: String, type: String) => Change

Convert a code block into a normal block (paragraph, etc).

changes.unwrapCodeBlock

plugin.changes.unwrapCodeBlock(change: Change, type: String) => Change

Convert current code block into a normal block (paragraph, etc).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].