Giter VIP home page Giter VIP logo

rich-markdown-editor's Introduction

npm version CircleCI Join the community on Spectrum Formatted with Prettier

rich-markdown-editor

A React and Slate based editor that powers the Outline wiki and can also be used for displaying content in a read-only fashion. The editor is WYSIWYG and includes many formatting tools whilst retaining the ability to write markdown shortcuts inline and output Markdown.

Usage

import Editor from "rich-markdown-editor";

<Editor
  defaultValue="Hello world!"
/>

See a working example in the example directory.

Props

defaultValue

A markdown string that represents the initial value of the editor. Use this to prop to restore previously saved content for the user to continue editing.

placeholder

Allows overriding of the placeholder text displayed in the main body content. The default is "Write something nice…".

readOnly

With readOnly set to false the editor is optimized for composition. When true the editor can be used to display previously written content – headings gain anchors, a table of contents displays and links become clickable.

toc

With toc set to true the editor will display a table of contents for headings in the document. This is particularly useful for larger documents and allows quick jumping to key sections.

plugins

Allows additional Slate plugins to be passed to the underlying Slate editor.

schema

Allows additional Slate schema to be passed to the underlying Slate editor.

theme

Allows overriding the inbuilt theme to brand the editor, for example use your own font face and brand colors to have the editor fit within your application. See the inbuilt theme for an example of the keys that should be provided.

Callbacks

uploadImage

If you want the editor to support images then this callback must be provided. The callback should accept a single File object and return a promise the resolves to a url when the image has been uploaded to a storage location, for example S3. eg:

<Editor
  uploadImage={async file => {
    const result = await s3.upload(file);
    return result.url;
  }}
/>

onSave({ done: boolean })

This callback is triggered when the user explicitly requests to save using a keyboard shortcut, Cmd+S or Cmd+Enter. You can use this as a signal to save the document to a remote server.

onCancel

This callback is triggered when the Cmd+Escape is hit within the editor. You may use it to cancel editing.

onChange

This callback is triggered when the contents of the editor changes, usually due to user input such as a keystroke or using formatting options. You may use this to locally persist the editors state, see the inbuilt example.

onImageUploadStart

This callback is triggered before uploadImage and can be used to show some UI that indicates an upload is in progress.

onImageUploadStop

Triggered once an image upload has succeeded or failed.

onSearchLink(term: string)

The editor provides an ability to search for links to insert from the formatting toolbar. If this callback is provided it should accept a search term as the only parameter and return a promise that resolves to an array of SearchResult objects. eg:

<Editor
  onSearchLink={async searchTerm => {
    const results = await MyAPI.search(searchTerm);

    return results.map(result => {
      title: result.name,
      url: result.url
    })
  }}
/>

onClickLink(href: string)

This callback allows overriding of link handling. It's often the case that you want to have external links open a new window whilst internal links may use something like react-router to navigate. If no callback is provided then default behavior will apply to all links. eg:

import { history } from "react-router";

<Editor
  onClickLink={href => {
    if (isInternalLink(href)) {
      history.push(href);
    } else {
      window.location.href = href;
    }
  }}
/>

renderNode

This callback allows overriding of the inbuilt renderNode – if a component is returned from the callback then it will be used instead of the default implementation. See the Slate documentation for an example.

renderPlaceholder

This callback allows overriding of the inbuilt renderPlaceholder – if a callback is provided then it will be used instead of the default implementation. See the Slate documentation for an example.

Contributing

This project uses yarn to manage dependencies. You can use npm however it will not respect the yarn lock file and may install slightly different versions.

yarn install

When running in development webpack-serve is included to serve an example editor with hot reloading. After installing dependencies run yarn start to get going.

License

This project is BSD licensed.

rich-markdown-editor's People

Contributors

jorilallo avatar tommoor avatar

Watchers

 avatar  avatar

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.