• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    TypeScript
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Remark plugin to compile Markdown as a slate 0.50+ compatible object.

remark-slate

Transform the contents of a slate 0.50+ editor into markdown and back again.

Downloads Size

remark plugin to compile Markdown as a Slate 0.50+ compatible object.

Usage

Slate object to Markdown:

remark-slate exports an opinionated serialize function that is meant to be invoked with a slate 0.50+ state object and will transform the object into a markdown document.

import { serialize } from 'remark-slate';

export default ({ onChange }) => {
  const [value, setValue] = useState(initialValue);

  const handleChange = useCallback((nextValue) => {
    setValue(nextValue);
    // serialize slate state to a markdown string
    onChange(value.map((v) => serialize(v)).join(''));
  }, [onChange]);

  return (
    <Slate editor={editor} value={value} onChange={handleChange}>
      <Editable
        renderElement={renderElement}
        renderLeaf={renderLeaf}
        placeholder="Enter some rich text…"
        ...
      />
      ...
    </Slate>
  );
};

Markdown to Slate object:

When deserializing from markdown to slate, this package is meant to be used with remark-parse and unified.

Our JS looks something like this:

import fs from 'fs';
import unified from 'unified';
import markdown from 'remark-parse';
import slate from 'remark-slate';

unified()
  .use(markdown)
  .use(slate)
  .process(fs.readFileSync('example.md'), (err, file) => {
    if (err) throw err;
    console.log({ file });
  });

And example.md looks like this:

# Heading one

## Heading two

### Heading three

#### Heading four

##### Heading five

###### Heading six

Normal paragraph

_italic text_

**bold text**

~~strike through text~~

[hyperlink](https://jackhanford.com)

> A block quote.

- bullet list item 1
- bullet list item 2

1. ordered list item 1
1. ordered list item 2

Results in the following Slate object

Reveal
[
  {
    "type": "heading_one",
    "children": [
      {
        "text": "Heading one"
      }
    ]
  },
  {
    "type": "heading_two",
    "children": [
      {
        "text": "Heading two"
      }
    ]
  },
  {
    "type": "heading_three",
    "children": [
      {
        "text": "Heading three"
      }
    ]
  },
  {
    "type": "heading_four",
    "children": [
      {
        "text": "Heading four"
      }
    ]
  },
  {
    "type": "heading_five",
    "children": [
      {
        "text": "Heading five"
      }
    ]
  },
  {
    "type": "heading_six",
    "children": [
      {
        "text": "Heading six"
      }
    ]
  },
  {
    "type": "paragraph",
    "children": [
      {
        "text": "Normal paragraph"
      }
    ]
  },
  {
    "type": "paragraph",
    "children": [
      {
        "text": "italic text",
        "italic": true
      }
    ]
  },
  {
    "type": "paragraph",
    "children": [
      {
        "text": "bold text",
        "italic": true
      }
    ]
  },
  {
    "type": "paragraph",
    "children": [
      {
        "text": "strike through text",
        "strikeThrough": true
      }
    ]
  },
  {
    "type": "paragraph",
    "children": [
      {
        "type": "link",
        "link": "https://jackhanford.com",
        "children": [
          {
            "text": "hyperkink"
          }
        ]
      }
    ]
  },
  {
    "type": "block_quote",
    "children": [
      {
        "type": "paragraph",
        "children": [
          {
            "text": "A block quote."
          }
        ]
      }
    ]
  },
  {
    "type": "ul_list",
    "children": [
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "text": "bullet list item 1"
              }
            ]
          }
        ]
      },
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "text": "bullet list item 2"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "ol_list",
    "children": [
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "text": "ordered list item 1"
              }
            ]
          }
        ]
      },
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "text": "ordered list item 2"
              }
            ]
          }
        ]
      }
    ]
  }
]

Miscellaneous

remark-slate makes some assumptions around unordered and ordered lists, the package pairs nicely with slate-edit-list

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. The project will be rebuilt upon changes.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

License (MIT)

WWWWWW||WWWWWW
 W W W||W W W
      ||
    ( OO )__________
     /  |           \
    /o o|    MIT     \
    \___/||_||__||_|| *
         || ||  || ||
        _||_|| _||_||
       (__|__|(__|__|

Copyright Β© 2020-present Jack Hanford, [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

next-offline

make your Next.js application work offline using service workers via Google's workbox
JavaScript
1,589
star
2

trends

ultra high performance github trending application
TypeScript
486
star
3

react-drag-drawer

A responsive mobile drawer that is draggable on mobile, and falls back to a modal on desktop
JavaScript
157
star
4

chirp

🐦 A cross platform twitter application
JavaScript
126
star
5

facebook-data-parser

A node app for parsing facebook data and outputting pretty graphs
JavaScript
105
star
6

github-native

πŸ“± mobile github client built with react-native
Objective-C
95
star
7

react-kanban

Beautiful Kanban implementation built on react-motion
JavaScript
42
star
8

await-exec

Small wrapper around node's child_process exec command, allowing it to easily be used with async/await
JavaScript
29
star
9

Instachrome

πŸ“Έ Browse Instagram from anywhere
JavaScript
28
star
10

uber-chrome

πŸš— Chrome extension allowing you to call an Uber from your desktop
JavaScript
22
star
11

bundle-cop

πŸš“ compare webpack stats between branches
JavaScript
20
star
12

Veneer

A simple chrome extension for writing custom CSS on all websites
JavaScript
17
star
13

defer-render-hoc

defer expensive react renders until the next two rAF's
JavaScript
16
star
14

personal-website

My personal website, it's also a PWA
TypeScript
16
star
15

angular-notify

A super tiny angular service with a easy API for using browser notifications.
JavaScript
15
star
16

react-fab-fan

Floating action button fan built with react and react-motion
JavaScript
14
star
17

next-static-manifest

Create a static page manifest of your Next.js exported html pages, allowing you to route to dynamic HTML pages
TypeScript
13
star
18

react-page-transition

drop in react page transition component
JavaScript
12
star
19

add-component

Generate a PureComponent or Functional Component, stylehseet and a test in one command
JavaScript
11
star
20

angular-vdom

angular .component() wrapper for virtual-dom components
JavaScript
10
star
21

use-loadable

React hook for knowing when an async function is loading or had an error
JavaScript
9
star
22

react-tooltip-portal

Small unopinionated react tooltip library that utilizes React 16's Portal API
JavaScript
9
star
23

angular-toast

Micro angular pop up library
HTML
8
star
24

render-react-from-cms

render react components that are intertwined in wysiwyg output
JavaScript
7
star
25

bi-directional-mfe

Webpack 5 Microfrontend, with Relay hooks and React Suspense
JavaScript
7
star
26

angular-phone-input

An easy to use directive for formatting / capturing phone numbers
HTML
6
star
27

react-flick-list

react bindings for kinetic scrolling
JavaScript
6
star
28

react-scroll-listen

efficiently save the scroll position of the document.body in React
JavaScript
6
star
29

cloudinary-export

streamingly export all images from cloudinary
JavaScript
5
star
30

simple-angular-dialog

Small library for creating dynamic modals with angularjs
JavaScript
5
star
31

await-wrap

use async/await without try/catch blocks
JavaScript
4
star
32

trends-sidebar

Chrome extension for trends.now.sh
JavaScript
4
star
33

animate

drop in, easy to use, natural looking animations with 0 config
JavaScript
4
star
34

website-performance

Gather common performance metrics from a website like Time To Interactive (TTI) and DOMContentLoaded
JavaScript
4
star
35

react-document-visibility

functional react component that re renders and informs children when the document is currently focussed or not
JavaScript
4
star
36

angular-sidebar

super small, mobile ready, vanilla angular sidebar component
JavaScript
4
star
37

pipe-fns

helper function enabling easy functional piping
JavaScript
3
star
38

now-playing

GraphQL + The movie database + Apollo & Next.js
JavaScript
3
star
39

pnpm-peer-deps

JavaScript
3
star
40

relay-swc-jest

TypeScript
3
star
41

mfe-poc

Simple project implementing a Module Federation Micro frontend
JavaScript
3
star
42

ci-github

easily comment on github commits / PR's from CircleCI or TravisCI
JavaScript
3
star
43

react-pinch-to-zoom

JavaScript
3
star
44

check-in

react native + yelp fusion API
JavaScript
3
star
45

sink

Store a local files/directories in iCloud drive ☁️
JavaScript
3
star
46

miniflare-shared-test-environment

Bug with r2_persist / jest-environment-miniflare
JavaScript
3
star
47

next-version-file

TypeScript
3
star
48

fast-flix

set playback speed of any HTML5 video on the internet
JavaScript
3
star
49

install-resolver

never guess whether a project is using yarn or npm again
JavaScript
3
star
50

credit-cards-react

Fork of react-credit-cards with css-in-js support
JavaScript
3
star
51

worker-rp-pages

TypeScript
3
star
52

remove-cors

Small Proxy for removing CORs headers
JavaScript
3
star
53

intersection-observer-image-grid

simple example using intersection-observer's in a react application
JavaScript
3
star
54

scrolltop-on-mount

react HOC that resets window scrollTop on mount
JavaScript
2
star
55

react-freeze-body

Declaratively apply overflow: hidden to the document.body
JavaScript
2
star
56

tinder-chrome

browse tinder from anywhere using this nifty chrome extension
JavaScript
2
star
57

react-zipcode

micro zipcode input with validation, mobile keypad keyboard built for react
JavaScript
2
star
58

apple-maps

small repo demonstrating how to recreate part of Apple maps native UI using web technology
JavaScript
2
star
59

array-dedupe

remove duplicated instances from an array by object key values
JavaScript
2
star
60

react-touchable-component

Touchable / draggable react component with an easy to use API
JavaScript
2
star
61

react-flexbox-helpers

Helper components for quickly using flexbox with React
JavaScript
2
star
62

preload-component

preload an array of image URL's the react way
JavaScript
2
star
63

add-deploy

generate circleci deployment scripts for now and heroku hosted node apps
JavaScript
2
star
64

request-callback

requestIdleCallback polyfill
JavaScript
2
star
65

bug-swcMinify-next-12.1.1

JavaScript
2
star
66

react-state-component

functional react component that exposes an additional external state to children
JavaScript
2
star
67

is-webapp

Detect if website was launched from mobile phone homescreen
JavaScript
2
star
68

relay-swc-monorepo

TypeScript
2
star
69

react-resize-width

Notify a component in react when the document.body is resized
JavaScript
2
star
70

relay-compiler-ci

TypeScript
2
star
71

many-workers

JavaScript
2
star
72

add-shallow

easily generate a shallow render test with one command
JavaScript
2
star
73

angular-disable-inflight

Angular directive for disabling elements while requests are in flight
JavaScript
2
star
74

next-on-pages-42

TypeScript
2
star
75

12.2-exports

JavaScript
2
star
76

react-image-loaded

Add a nice animation as soon as an image is loaded
JavaScript
2
star
77

required-parameter

require parameters when functions are invoked
JavaScript
2
star
78

react-github-badge

A 'Star on github' badge made for react
JavaScript
2
star
79

next-on-pages-32

TypeScript
2
star
80

many-relay-next

TypeScript
2
star
81

cacher

chrome extension for overwriting and adding permanent cache headers on all assets
JavaScript
2
star
82

url-constructor

A small library for dynamically matching urls with parameters
JavaScript
2
star
83

website-performance-hoc

react bindings for the website-performance NPM module
JavaScript
2
star
84

dot

setup / startup scripts for new computers / HDD's
Shell
2
star
85

twitter-popup

JavaScript
2
star
86

full-height-hoc

Loop over elements so a page can use flexbox height
JavaScript
2
star
87

storybook-deploy

JavaScript
2
star
88

react-flip-list

react <List /> component with FLIP animations built in
JavaScript
2
star
89

react-commit

lazily execute async functions on user initiated action
JavaScript
2
star
90

react-sherlock

react input with nlp superpowers
JavaScript
1
star
91

angular-sherlock

JavaScript
1
star
92

Bookmarker

A simple chrome extenstion to open all my bookmarks in the background.
JavaScript
1
star
93

angular-date-input

angular directive to streamline inputting dates
JavaScript
1
star
94

hanford.github.io

Home page
HTML
1
star
95

chrome-version

library for getting major chrome version from a user agent string
JavaScript
1
star
96

angular-faux-loader

Directive for displaying a loading message while data is coming in
JavaScript
1
star
97

angular-sticky-thead

JavaScript
1
star
98

angular-restrict-number

Directive for enforcing inpuit's ngModel is always a number
JavaScript
1
star
99

angular-maxlength

Small directive for _really_ enforcing maxlength
JavaScript
1
star
100

MobileGit-Server

JavaScript
1
star