All Projects → bytedance → Bytemd

bytedance / Bytemd

Licence: mit
A hackable Markdown editor component built with Svelte

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Bytemd

Macdown
Open source Markdown editor for macOS.
Stars: ✭ 8,855 (+1249.85%)
Mutual labels:  markdown, markdown-editor, markdown-viewer
Markitdown
📱 A React app to preview and edit Markdown✍. You can also export it as HTML.
Stars: ✭ 26 (-96.04%)
Mutual labels:  markdown, markdown-editor, markdown-viewer
Marcdown
👻 Lightweight realtime markdown viewer and editor - Simple, clean and beautiful https://liyasthomas.github.io/marcdown
Stars: ✭ 345 (-47.41%)
Mutual labels:  markdown, markdown-editor, markdown-viewer
Mditor
📝 [ M ] arkdown + E [ ditor ] = Mditor
Stars: ✭ 523 (-20.27%)
Mutual labels:  markdown, markdown-editor, markdown-viewer
For Editor
for-editor - A markdown editor based on React
Stars: ✭ 358 (-45.43%)
Mutual labels:  markdown, markdown-editor
Marky
A markdown editor built with Electron and React
Stars: ✭ 355 (-45.88%)
Mutual labels:  markdown, markdown-editor
Marker
🖊 A gtk3 markdown editor
Stars: ✭ 644 (-1.83%)
Mutual labels:  markdown, markdown-editor
Justwrite
一款支持同步滑动预览的跨平台Markdown编辑器
Stars: ✭ 411 (-37.35%)
Mutual labels:  markdown, markdown-editor
Grav Plugin Admin
Grav Admin Plugin
Stars: ✭ 316 (-51.83%)
Mutual labels:  markdown, markdown-editor
React Md Editor
A simple markdown editor with preview, implemented with React.js and TypeScript.
Stars: ✭ 374 (-42.99%)
Mutual labels:  markdown, markdown-editor
Moeditor
(discontinued) Your all-purpose markdown editor.
Stars: ✭ 4,003 (+510.21%)
Mutual labels:  markdown, markdown-editor
Githuber Md
Markdown editor plugin for WordPress.
Stars: ✭ 353 (-46.19%)
Mutual labels:  markdown, markdown-editor
Markdown Mode
Emacs Markdown Mode
Stars: ✭ 634 (-3.35%)
Mutual labels:  markdown, markdown-editor
Notes
✎ Distraction-free notes and writing
Stars: ✭ 363 (-44.66%)
Mutual labels:  markdown, markdown-editor
Issues
Caret issues
Stars: ✭ 326 (-50.3%)
Mutual labels:  markdown, markdown-editor
Lookatme
An interactive, terminal-based markdown presenter
Stars: ✭ 392 (-40.24%)
Mutual labels:  markdown, markdown-viewer
Markdown Viewer
Markdown Viewer / Browser Extension
Stars: ✭ 497 (-24.24%)
Mutual labels:  markdown, markdown-viewer
Django Pagedown
A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
Stars: ✭ 500 (-23.78%)
Mutual labels:  markdown, markdown-editor
Phodit
Phodal's markdown/ebook editor with MicroFrontend & Web Components
Stars: ✭ 301 (-54.12%)
Mutual labels:  markdown, markdown-editor
Markdown Preview Enhanced
One of the 'BEST' markdown preview extensions for Atom editor!
Stars: ✭ 3,478 (+430.18%)
Mutual labels:  markdown, markdown-editor

ByteMD

test

ByteMD is a Markdown editor component built with Svelte. It could also be used in other libraries/frameworks such as React, Vue and Angular.

Features

  1. Lightweight and framework agnostic: ByteMD is built with Svelte. It compiles to vanilla JS DOM manipulation without importing any UI Framework runtime bundle, which makes it lightweight, and easily adapted to other libraries/frameworks.
  2. Easy to extend: ByteMD has a plugin system to extend the basic Markdown syntax, which makes it easy to add additional features such as code syntax highlight, math equation and Mermaid flowcharts. You can also write your own plugin if these ones don't meet your needs.
  3. Secure by default: Cross-site scripting(XSS) attack such as <script> and <img onerror> have been correctly handled by ByteMD. No need to introduce extra DOM sanitize steps.
  4. SSR compatiable: ByteMD could be used in the Server-side rendering(SSR) environment without extra config. SSR is widely used in some cases due to its better SEO and fast time-to-content in slow network connection.

Installation

Package Status Description
bytemd npm gzip size Svelte/Vanilla JS component
@bytemd/react npm gzip size React component
@bytemd/vue npm gzip size Vue component

Legacy browsers support

The default entry of NPM package only supports modern browsers. There are two ways to make legacy browsers (IE9+) work:

  1. Compile it with ESNext -> ES5 transpilers, such as Babel
  2. Use the ES5 bundle(dist/index.es5.js)

Notice that polyfills are not included, and should be imported manually, see the legacy browser example.

Usage

There are two components: Editor and Viewer. Editor is the Markdown editor, as the name suggests; Viewer is commonly used to display rendered Markdown results without editing.

Before using the component, remember to import CSS file to make styles correct:

import 'bytemd/dist/index.min.css';

Svelte

<script>
  import { Editor, Viewer } from 'bytemd';
  import gfm from '@bytemd/plugin-gfm';

  let value;
  const plugins = [
    gfm(),
    // Add more plugins here
  ];

  function handleChange(e) {
    value = e.detail.value;
  }
</script>

<template>
  <Editor {value} {plugins} on:change={handleChange} />
</template>

React

import { Editor, Viewer } from '@bytemd/react';
import gfm from '@bytemd/plugin-gfm';

const plugins = [
  gfm(),
  // Add more plugins here
];

const App = () => {
  const [value, setValue] = useState('');

  return (
    <Editor
      value={value}
      plugins={plugins}
      onChange={(v) => {
        setValue(v);
      }}
    />
  );
};

Vue

<template>
  <Editor :value="value" :plugins="plugins" @change="handleChange" />
</template>

<script>
import { Editor, Viewer } from '@bytemd/vue';
import gfm from '@bytemd/plugin-gfm';

const plugins = [
  gfm(),
  // Add more plugins here
];

export default {
  components: { Editor },
  data() {
    return { value: '', plugins };
  },
  methods: {
    handleChange(v) {
      value = v;
    },
  },
};
</script>

Vanilla JS

import { Editor, Viewer } from 'bytemd';
import gfm from '@bytemd/plugin-gfm';

const plugins = [
  gfm(),
  // Add more plugins here
];

const editor = new Editor({
  target: document.body, // DOM to render
  props: {
    value: '',
    plugins,
  },
});

editor.$on('change', (e) => {
  editor.$set({ value: e.detail.value });
});

Options

Viewer

Key Type Description
value string (required) Markdown text
plugins BytemdPlugin[] ByteMD plugin list
sanitize (schema: Schema) => Schema Sanitize strategy

Editor

Editor component also accepts the options of Viewer for preview. Besides that, there are some other options:

Key Type Description
mode split, tab, auto Editor display mode
previewDebounce number Debounce time (ms) for preview, default: 300
placeholder string Editor placeholder
editorConfig documentation CodeMirror editor config
locale i18n locale. Available locales could be found at bytemd/lib/locales
uploadImages function Specify how to upload images

Style customization

Editor

The default height of ByteMD Editor is 300px. It could be overrided by CSS:

.bytemd {
  height: calc(100vh - 200px);
}

The other styles could also be overrided, see the default style.

Viewer

There is no built-in styles for the Viewer. You could use third-party markdown themes, for example juejin-markdown-themes and github-markdown-css.

Technical details

ByteMD uses remark and rehype ecosystem to process Markdown. The complete process is as follows:

  1. The markdown text is parsed to an AST
  2. The Markdown AST could be manipulated by several remark plugins
  3. The Markdown AST is transformed to a HTML AST
  4. The HTML AST is sanitized for security reason
  5. The HTML AST could be manipulated by several rehype plugins
  6. The HTML AST is stringified to HTML
  7. Some extra DOM manipulation after the HTML being rendered

It could also be described as a flowchart:

process

The 2,5,7 steps are designed for user customization via ByteMD plugin API.

Plugins

Package Status Description
@bytemd/plugin-breaks npm gzip size Support breaks
@bytemd/plugin-footnotes npm gzip size Support footnotes
@bytemd/plugin-frontmatter npm gzip size Parse frontmatter
@bytemd/plugin-gemoji npm gzip size Support Gemoji shortcodes
@bytemd/plugin-gfm npm gzip size Support GFM (autolink literals, strikethrough, tables, tasklists)
@bytemd/plugin-highlight npm gzip size Highlight code blocks
@bytemd/plugin-highlight-ssr npm gzip size Highlight code blocks (SSR compatible)
@bytemd/plugin-math npm gzip size Support math formula
@bytemd/plugin-math-ssr npm gzip size Support math formula (SSR compatible)
@bytemd/plugin-medium-zoom npm gzip size Zoom images like Medium
@bytemd/plugin-mermaid npm gzip size Support Mermaid diagram

Write a plugin

TODO: plugin API not stable yet

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].