Coder Social home page Coder Social logo

smolijar / emily-editor Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 2.0 813 KB

React editor component for LMLs, like Markup 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.

License: BSD 2-Clause "Simplified" License

JavaScript 100.00%
editor lml lightweight-markup-language markdown asciidoc react component document livepreview synchronized-scrolling modular markup outline

emily-editor's Introduction

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.

emily-editor's People

Contributors

smolijar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

emily-editor's Issues

Autosave key

Generate autosave localStorage key based on given key or initial content, to allow saving multiple instances.

Basic autocomplete

Does not need to have all features. Implement e.g. hrefs for headings, prepare an interface for extending.

It's ugly

  • leave dark theme, it might work on desktop but on web it looks like 12yo learned css; all almost all form inputs and textareas are actually white
  • stay pure, minimal, simple, spacious, clean
  • inspire thyself from existing projects, that look good SimpleMDE, Typora, Google Docs (outline)

Did you lot find anything visually impressive ✨ from similliar editors?

Comment your suggestions! :octocat:

Emoji support

Add short text emoji support :cat: 🐱 ala GitHub, Slack, ...

Refactor JSX styles

JSX styles take up most of the space in render method, which is not cool.

  • Extract into seperate funsctions, preferably files.
  • Consider using CSS preprocessor if available in JSX. Lot of redundancy in selectors
  • Seperate component and global styles

Fix console errors

There are some complains about key props, invalid prop types, funny html.

Links inside preview are not “clickable”

Links are rendered correctly as <a> tag, but its default action for left left click is blocked. User can open the link from browser’s context menu, but not by clicking or tapping on it.

Name

Be a good boy and give it a cool name!

Markup editor is boring, too general and ambiguous. People might think it's for XML.

Make it unique and related do lighweight markup languages 😐

Spellcheck

Browser spellchecking usually does not work in similar editors. Mostly because it is not a single textarea or set of them, but input elements are dynamically generated. Current code is not in any input most of the time.

Application solutions seems to be the only way. Would rather use an existing editor extension, than implement it myself. I could not get to work any of those I found for CM nor Ace.

Current implementation I did for CM sucks. Does not use context menu and does not fully integrate to cm

Cmd+C (copy) in preview panel does not work

When I select some text in the preview panel and hit Cmd+C to copy the selection, it does not copy it to the clipboard. However, when I open a context menu (right click) and click on “Copy” here, it does copy the selection to the clipboard. How’s that even possible…? 🙀

Browser: Firefox 55.0.3 on macOS

Return scrollbars

It feels really weird to have a scrollable area without scrollbars. Even when you don’t use scrollbars for actual scrolling, they are useful as an indicator where you are in the document (position of the scrollbar) and how it is long (height of the scrollbar).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.