Code Monkey home page Code Monkey logo

slate-markdown's Introduction

slate-markdown

Add live markdown preview to your Slate editor.


Demo: slate-markdown.spectrum.chat

Installation

npm install slate-markdown

Usage

import { Editor } from 'slate';
import MarkdownPlugin from 'slate-markdown';

const markdown = MarkdownPlugin();

<Editor
  plugins={[markdown]}
/>

Options

sizes

(default: ['2.441em', '1.953em', '1.563em', '1.25em', '1em'])

A list of sizes to use for the headings, the index + 1 is used for the level

const markdown = MarkdownPlugin({
  // This is the default:
  sizes: ['2.441em', '1.953em', '1.563em', '1.25em', '1em'],
  //       ^ h1       ^ h2       ^ h3       ^ h4      ^ h5
})

classnames

An object containing additional classnames to attach to the rendered components. Useful to adapt the styling.

const markdown = MarkdownPlugin({
  classnames: {
    // When a title is rendered it will now have a .custom-title className
    title: 'custom-title',
  }
})

Possible keys are for the object are:

'title' | 'bold' | 'italic' | 'punctuation' | 'code' | 'list' | 'hr' | 'url'

strict

(default: true)

This plugin uses PrismJS for highlighting the markdown. By default the Prism markdown grammar extends the markup grammar, and thusly supports things like <tag>s, <script>s etc.

This option disables the inherited HTML grammar, only allowing actual markdown to pass through. Set this to false if you want to highlight HTML within the markdown.

Roadmap

This plugin is fairly complete (± small bugs) and used in production by us at Spectrum. Nevertheless, there's some features we are looking to implement in the future:

  • GitHub-style codeblocks with triple backticks

If you want to help out with any of these, please feel free to submit PRs!

Development

Development of this plugin is done via the example/ app. Here's how to get the plugin building locally:

# Download the repo
git clone https://github.com/withspectrum/slate-markdown
# Install the dependencies of the package
cd slate-markdown
npm install
# Start the build process with a watcher
npm run build -- --watch # (notice the extra --, you need those!)

To see your local version of the plugin locally open another terminal tab and run these commands:

# Get into the example folder (this is assuming you're already in the slate-markdown folder)
cd example
# Install the example dependencies
npm install
# Run the example locally, this should open a browser tab
npm start
# If this doesn't open a browser tab open http://localhost:3000 manually

Now whenever you change the package the example app will reload automatically with the new code.

License

Licensed under the MIT License, Copyright ©️ 2017 Maximilian Stoiber. See LICENSE.md for more information.

Most of this code was taken directly from the Slate examples, thanks to @ianstormtaylor. Source for the example copied here.

slate-markdown's People

Contributors

mxstbr avatar

Watchers

James Cloos avatar Will Robbins 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.