npm install slate-markdown
import { Editor } from 'slate';
import MarkdownPlugin from 'slate-markdown';
const markdown = MarkdownPlugin();
<Editor
plugins={[markdown]}
/>
(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
})
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'
(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.
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 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.
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.