Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

md-editor-rt

Package Overview
Dependencies
Maintainers
1
Versions
231
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

md-editor-rt

Markdown editor for react, developed by jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...

  • 1.6.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

md-editor-rt

English | 中文

Markdown editor for react, developed in jsx and typescript.

  • Documentation and demo:Go

  • Use it online:Go

  • The same series editor for vue3:md-editor-v3

Features

  • Toolbar, screenfull or screenfull in web pages and so on.
  • Themes, Built-in default and dark themes.
  • Shortcut key for editor.
  • Beautify your content by prettier(only for markdown content, not the code and other text).
  • Multi-language, build-in Chinese and English(default: Chinese).
  • Upload picture, paste or clip the picture and upload it.
  • Render article directly(no editor, no event listener, only preview content).
  • Preview themes, support defalutvuepressgithub styles(not identical).
  • mermaid(>=1.3.0).
  • katex mathematical formula(>=1.4.0).

More features are developing, if you have some ideas or find issues, please tell me~

Preview

Default themeDark themePreview only

Apis

Props

nametypedefaultdescription
modelValueString''Markdown content
theme'light' | 'dark''light'Change editor theme
editorClassString''
hljsObjectnullHighlight instance, editor will not insert script of it, but you need to import highlight code style by yourself
highlightJsStringhighlight.js@11.2.0HighlightJs url
highlightCssStringatom-one-dark@11.2.0Highlight code style
historyLengthNumber10The max length of history(if it is too big, editor will use more RAM)
pageFullScreenBooleanfalseScreenfull in web page
previewBooleantruePreview content in editor
htmlPreviewBooleanfalsePreview html in editor
previewOnlyBooleanfalseOnly render article content, no toolbar, no edit area
languageString'zh-CN'Build-in language('zh-CN','en-US')
languageUserDefinedObject{key: StaticTextDefaultValue}Expand language, update language api to your key
toolbarsArray[toolbars]Show some item of toolbars, all keyssee toolbars below
toolbarsExcludeArray[]Don't show some item of toolbars, all keystoolbars
prettierBooleantrueUse prettier to beautify content or not
prettierCDNStringstandalone@2.4.0
prettierMDCDNStringparser-markdown@2.4.0
cropperCssStringcropper.min.css@1.5.12Cropper css url
cropperJsStringcropper.min.js@1.5.12Cropper js url
iconfontJsStringiconfontIcon url
editorIdStringmd-editor-rtEditor id, also the html id, it is used when there are more than two editors
tabWidthNumber2One tab eq some space
showCodeRowNumberBooleanfalseShow row number for code block or not
screenfullObjectnullScreenfull instance, editor will not insert script of it
screenfullJsStringscreenfull@5.1.0Screenfull js url
previewTheme'default' | 'github' | 'vuepress''default'Preview themes
styleCSSProperties{}Editor's inline style
mermaidObjectundefinedmermaid instance
mermaidJsStringmermaid@8.13.5mermaidJs url
noMermaidBooleanfalsedo not use mermaid
placeholderString''
katexObjectundefinedkatex instance(you need import css by yourself.)
katexJsStringkatex.min.js@0.15.1katexJs url
katexCssStringkatex.min.css@0.15.1katexCss url
noKatexBooleanfalsedo not use katex
defToolbarsArray<DropdownToolbar | NormalToolbar>nullCustomize Toolbar, for more usage, please refer to docs and emoji
extensionsArray[]marked extensions

mark and emoji extensions

mark and Emoji extension

[toolbars]

[
  'bold',
  'underline',
  'italic',
  '-',
  'strikeThrough',
  'title',
  'sub',
  'sup',
  'quote',
  'unorderedList',
  'orderedList',
  '-',
  'codeRow',
  'code',
  'link',
  'image',
  'table',
  'mermaid',
  'katex',
  '-',
  'revoke',
  'next',
  'save',
  '=',
  'pageFullscreen',
  'fullscreen',
  'preview',
  'htmlPreview',
  'catalog',
  'github'
];

You can sort the toolbar as you like, split tools by '-', the left and right toolbars are divided by '='

Expand language, you need to replace all the content here:

[StaticTextDefaultValue]

export interface ToolbarTips {
  bold?: string;
  underline?: string;
  italic?: string;
  strikeThrough?: string;
  title?: string;
  sub?: string;
  sup?: string;
  quote?: string;
  unorderedList?: string;
  orderedList?: string;
  codeRow?: string;
  code?: string;
  link?: string;
  image?: string;
  table?: string;
  mermaid?: string;
  katex?: string;
  revoke?: string;
  next?: string;
  save?: string;
  prettier?: string;
  pageFullscreen?: string;
  fullscreen?: string;
  catalog?: string;
  preview?: string;
  htmlPreview?: string;
  github?: string;
  '-'?: string;
  '='?: string;
}

export interface StaticTextDefaultValue {
  // Toolbar hover tips(html title)
  toolbarTips?: ToolbarTips;
  // h1-h6 dropdown menu item
  titleItem?: {
    h1?: string;
    h2?: string;
    h3?: string;
    h4?: string;
    h5?: string;
    h6?: string;
  };
  imgTitleItem?: {
    link: string;
    upload: string;
    clip2upload: string;
  };
  // The modal tips of add link or upload picture
  linkModalTips?: {
    title?: string;
    descLable?: string;
    descLablePlaceHolder?: string;
    urlLable?: string;
    UrlLablePlaceHolder?: string;
    buttonOK?: string;
  };
  // The modal tips of clip the picture
  clipModalTips?: {
    title?: string;
    buttonUpload?: string;
  };
  // Copy code tips
  copyCode?: {
    text?: string;
    tips?: string;
  };
  mermaid?: {
    flow?: string;
    sequence?: string;
    gantt?: string;
    class?: string;
    state?: string;
    pie?: string;
    relationship?: string;
    journey?: string;
  };
  // 1.4.0
  katex?: {
    // formula inline
    inline: string;
    // formula block
    block: string;
  };
}

Event

nametypedescription
onChange(v: string) => voidContent changed event(bind to oninput of textarea)
onSave(v: string) => voidSave Content event, ctrl+sand click button will trigger
onUploadImg(files: FileList, callback: function) => voidUpload picture event, when picture is uploading the modal will not close, please provide right urls to the callback function
onHtmlChanged(h: string) => voidCompile markdown successful event, you can use it to get the html code
onGetCatalog(list: HeadList[]) => voidGet catalogue of article
markedHeading(text: string,level: 1-6,raw: string, slugger: Slugger) => stringmarked head renderer methods
markedHeadingId(text: string, level: number) => stringtitle ID generator
sanitize(html: string) => stringSanitize the html, prevent XSS.
markedImage(href: string, title: string, desc: string) => stringOverrides the html element structure of the default generated picture

If markedHeading is overridden, be sure to tell the editor the algorithm for generating the title ID by marketheadingid.

Shortcut key

keyfunctiondescription
TABinsert spaceInsert space, the length eq tabWidth, default: 2, support multiline
SHIFT + TABdelete space, setting is the same as Tab
CTRL + CcopyWhen selected, copy the selected content. When not selected, copy the content of the current line
CTRL + XshearWhen selected, cut the selected content. When not selected, cut the current line
CTRL + DdeleteWhen selected, delete the selected content. When not selected, delete the current line
CTRL + SsaveTrigger onSave event
CTRL + Bbold text**bold**
CTRL + Uunderline<u>underline</u>
CTRL + Iitalic*italic*
CTRL + 1-6h1-h6# title
CTRL + ↑superscript<sup>superscript</sup>
CTRL + ↓subscript<sub>subscript</sub>
CTRL + Qquote> quote
CTRL + Oordered list1. ordered list
CTRL + Llink[link](https://github.com/imzbf/md-editor-v3)
CTRL + ZwithdrawWithdraw history in editor, not the function of system
CTRL + SHIFT + Sline-through~line-through~
CTRL + SHIFT + Uunordered list- unordered list
CTRL + SHIFT + Ccode block
CTRL + SHIFT + Ipicture![picture](https://imbf.cc)
CTRL + SHIFT + ZforwardForward history in editor, not the function of system
CTRL + SHIFT + FBeautify
CTRL + ALT + Ccode row
CTRL + SHIFT + ALT + Ttable|table|

Internal components

Before 1.x, they are used as attributes of the editor component, eg: Editor.DropdownToolbar. For more examples, refer to document.

NormalToolbar

Editor.NormalToolbar

  • title: string, not necessary, the tips when hover toolbar;
  • trigger: string | JSX.Element, necessary, it is usually an icon, which is displayed on the toolbar;
  • onClick: (e: MouseEvent) => void, necessary.

DropdownToolbar

Editor.DropdownToolbar

  • title: string, not necessary, the tips when hover toolbar;
  • visible: boolean, necessary;
  • trigger: string | JSX.Element, necessary, it is usually an icon, which is displayed on the toolbar;
  • onChange: (visible: boolean) => void, necessary;
  • overlay: string | JSX.Element, necessary, contents in the drop-down box.

Catalogue

Editor.Catalog

  • editorId: string, necessary, editor's editorId, used to register listening events;
  • class: string, not necessary;
  • markedHeadingId: MarkedHeadingId, not necessary, same as editor;
  • scrollElement: string | HTMLElement, not necessary, it is an element selector when its type is string. When previewOnly eq true, it is usually set to document.documentElement.

Some examples

Jsx module

import { useState } from 'react';
import Editor from 'md-editor-rt';
import 'md-editor-rt/lib/style.css';

export default function App() {
  const [text, setText] = useState('hello md-editor-rt!');

  return (
    <Editor
      modelValue={text}
      onChange={(modelValue) => {
        setText(modelValue);
      }}
    />
  );
}

Upload picture

Tips:When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!

async onUploadImg(files: FileList, callback: (urls: string[]) => void) {
  const res = await Promise.all(
    Array.from(files).map((file) => {
      return new Promise((rev, rej) => {
        const form = new FormData();
        form.append('file', file);

        axios
          .post('/api/img/upload', form, {
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          })
          .then((res) => rev(res))
          .catch((error) => rej(error));
      });
    })
  );

  callback(res.map((item: any) => item.data.url));
}

More

Go to the example page: go

Keywords

FAQs

Package last updated on 10 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc