emily-editor

0.9.5 • Public • Published

Emily

Travis build Dependencies Status Dev-dependencies Status npm version

Emily is a React editor component for LMLs, like Markdown or Asciidoc. The focus of the project is to provide fluent efficient interface for advanced users, who are familliar with using IDE or coding text editors.

About Emily

Emily is an editor for LML document formats, currently supporting few languages. Editor works with a document-format abstraction and new modules can be added to make use of existing features:

  • Syntax highlight
  • Live document preview
    • Review the result as you type in split screen view or just browse the preview
  • Outline preview
    • Section lookup in source code
    • Section reordering -- drag & drop whole sections
  • Command palette
    • Make use of a command palette you know from coding editors
  • Autosave
    • Session is stored in localStorage, retrieved when lost.

Emily editor is part of an implementation for the Git-based Wiki System and its UI for the prototype has been developed in cource UI Design on the faculty.

Install

npm install --save emily-editor

Usage

  1. Include node_modules/emily-editor/dist/style.css
  2. Include node_modules/emily-editor/dist/script.js
  3. Use component:
import Emily from 'emily-editor'
// ...
 
ReactDOM.render(
  <Emily />,
  document.getElementById('container')
);

For examples, see pages

Props

content

Initial content of the editor

language

Language mode object. You can use generateMode to create a mode from existing modules.

import Emily, { generateMode } from 'emily-editor'
// ...
 
ReactDOM.render(
  <Emily language={generateMode(/*...*/)} />,
  document.getElementById('container')
);

listFiles(pfx)

List available relative files with path prefix pfx. Returns a Array<String> in a Promise.

This can be used for autosuggestions by a mode.

width

Lock editor's width and vorbid it to fill the container.

height

Lock editor's height and vorbid it to fill the container.

Methods

getValue

Return current value of the editor.

generateMode(input)

Input can be either:

  • name of the mode, e.g. asciidoc
  • any file path, e.g. foo/bar/baz.adoc

As a result a language mode is generated.

  1. If the name or the extension matches an existing LML mode, a proper full-featured mode is generated.
  2. If the name or the extension matches a mode supported by Ace editor, no special features for LML are provided, but editor features syntax highlight.
  3. Otherwise a plaintext editor is delivered. No syntax highlight.

Examples

Here are some examples of using the editor with generateMode function.

// asciidoc mode
<Emily language={generateMode('x.adoc')}>
<Emily language={generateMode('asciidoc')}>
<Emily language={generateMode('/xxx/weee.adoc')}>
 
// markdown mode
<Emily language={generateMode('markdown')}>
<Emily language={generateMode('a/b/c/d/foo.md')}>
 
// (unsupported) js mode
// only syntax highlight, missing features
<Emily language={generateMode('javascript')}>
<Emily language={generateMode('test.js')}>
 
// unrecognized mode
// working in plaintext mode
<Emily language={generateMode('foo/bar/baz')}>
<Emily language={generateMode('thisisnotanameofanymode')}>

Language modes

Take a look at asciidoc mode example.

name (string)

  • name of the mode

convert (func)

  • converting function to html from the raw markup

lineSafeInsert (func)

  • insert content in the line of markup without distorting the markup
  • the more lines you can cover the better
  • it is necessary to cover heading lines

postProcess (func)

  • modify preview DOM before render

renderJsxStyle (func)

  • add styles for preview

excludeOutlineItem (func)

  • exclude DOM Element from the outline

previewClassName (string)

  • set the CSS classname for the prevew container

Online demo

https://emily-editor.herokuapp.com/

License

Emily editor is licenced under the BSD License.

Dependencies (35)

Dev Dependencies (20)

Package Sidebar

Install

npm i emily-editor

Weekly Downloads

4

Version

0.9.5

License

ISC

Unpacked Size

719 kB

Total Files

63

Last publish

Collaborators

  • grissius