Code Monkey home page Code Monkey logo

react-markdown-editor's Introduction

React Markdown Editor logo

Build & Deploy NPM Download npm version

A markdown editor with preview, implemented with React.js and TypeScript.

React Markdown Editor

Migrate from @uiw/react-markdown-editor 4.x to 5.x.

Install

npm i @uiw/react-markdown-editor

Document

Official document demo preview (🇨🇳**镜像网站)

Basic Usage

import React from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';

const mdStr = `# This is a H1  \n## This is a H2  \n###### This is a H6`;

const Dome = () => {
  return (
    <MarkdownEditor
      value={mdStr}
      onChange={(value, viewUpdate) => {

      }}
    />
  )
};

export default Dome;

Controlled Usage

Open in CodeSandbox

import React, { useState } from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';

const mdStr = `# This is a H1  \n## This is a H2  \n###### This is a H6`;
export default function App() {
  const [markdown, setMarkdown] = useState(mdStr);
  return (
    <MarkdownEditor
      value={markdown}
      height="200px"
      onChange={(value, viewUpdate) => setMarkdown(value)}
    />
  );
}

Only Markdown Preview

Open in CodeSandbox

This markdown preview sub-component is a direct export @uiw/react-markdown-preview component, API documentation, please check @uiw/react-markdown-preview.

import React from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';

const mdStr = `# This is a H1  \n## This is a H2  \n###### This is a H6`;
function App() {
  return (
    <MarkdownEditor.Markdown source={mdStr} height="200px" />
  );
}

export default App;

Custom Toolbars

Open in CodeSandbox

import React from "react";
import MarkdownEditor from '@uiw/react-markdown-editor';

const title2 = {
  name: 'title2',
  keyCommand: 'title2',
  button: { 'aria-label': 'Add title text' },
  icon: (
    <svg width="12" height="12" viewBox="0 0 512 512">
      <path fill="currentColor" d="M496 80V48c0-8.837-7.163-16-16-16H320c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h37.621v128H154.379V96H192c8.837 0 16-7.163 16-16V48c0-8.837-7.163-16-16-16H32c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h37.275v320H32c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h160c8.837 0 16-7.163 16-16v-32c0-8.837-7.163-16-16-16h-37.621V288H357.62v128H320c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h160c8.837 0 16-7.163 16-16v-32c0-8.837-7.163-16-16-16h-37.275V96H480c8.837 0 16-7.163 16-16z" />
    </svg>
  ),
  execute: ({ state, view }) => {
    if (!state || !view) return;
    const lineInfo = view.state.doc.lineAt(view.state.selection.main.from);
    let mark = '#';
    const matchMark = lineInfo.text.match(/^#+/)
    if (matchMark && matchMark[0]) {
      const txt = matchMark[0];
      if (txt.length < 6) {
        mark = txt + '#';
      }
    }
    if (mark.length > 6) {
      mark = '#';
    }
    const title = lineInfo.text.replace(/^#+/, '')
    view.dispatch({
      changes: {
        from: lineInfo.from,
        to: lineInfo.to,
        insert: `${mark} ${title}`
      },
      // selection: EditorSelection.range(lineInfo.from + mark.length, lineInfo.to),
      selection: { anchor: lineInfo.from + mark.length },
    });
  },
};

const Dome = () => (
  <MarkdownEditor
    value="Hello Markdown!"
    height="200px"
    toolbars={[
      'bold', title2
    ]}
  />
);

export default Dome;

Disable preview feature

Open in CodeSandbox

import React from "react";
import MarkdownEditor from '@uiw/react-markdown-editor';

const Dome = () => (
  <MarkdownEditor
    value="Hello Markdown!"
    height="200px"
    enablePreview={false}
  />
);

export default Dome;

Support Nextjs

Use examples in nextjs.

Open in CodeSandbox #52 #224

npm install next-remove-imports
npm install @uiw/react-markdown-editor
// next.config.js
const removeImports = require('next-remove-imports')();
module.exports = removeImports({});
import dynamic from 'next/dynamic';
import '@uiw/react-markdown-editor/markdown-editor.css';
import '@uiw/react-markdown-preview/markdown.css';

const MarkdownEditor = dynamic(
  () => import("@uiw/react-markdown-editor").then((mod) => mod.default),
  { ssr: false }
);

function HomePage() {
  return (
    <div>
      <MarkdownEditor value="Hello Markdown!" />
    </div>
  );
}

export default HomePage;

Support dark-mode/night-mode

By default, the dark-mode is automatically switched according to the system. If you need to switch manually, just set the data-color-mode="dark" parameter for html Element.

<html data-color-mode="dark">
document.documentElement.setAttribute('data-color-mode', 'dark')
document.documentElement.setAttribute('data-color-mode', 'light')

Inherit custom color variables by adding .wmde-markdown-var selector.

const Demo = () => {
  return (
    <div>
      <div className="wmde-markdown-var"> </div>
      <MarkdownEditor value="Hello Markdown!" />
    </div>
  )
}

Props

  • value (string) - the raw markdown that will be converted to html (required)
  • visible?: boolean - Shows a preview that will be converted to html.
  • toolbars?: ICommand[] | string[] - Tool display settings.
  • toolbarsMode?: ICommand[] | string[] - Tool display settings.
  • onChange?:function(editor: IInstance, data: CodeMirror.EditorChange, value: string) - called when a change is made
  • onBlur?: function(editor: IInstance, event: Event) - event occurs when an object loses focus
  • onPreviewMode?: (isHide: boolean) => void - Edit mode and preview mode switching event
  • previewProps - react-markdown options
import { ReactCodeMirrorProps } from '@uiw/react-codemirror';
export interface IMarkdownEditor extends ReactCodeMirrorProps {
  className?: string;
  prefixCls?: string;
  /** The raw markdown that will be converted to html (**required**) */
  value?: string;
  /** Shows a preview that will be converted to html. */
  visible?: boolean;
  visibleEditor?: boolean;
  /** Override the default preview component */
  renderPreview?: (props: MarkdownPreviewProps, initVisible: boolean) => React.ReactNode;
  /** Preview expanded width @default `50%` */
  previewWidth?: string;
  /** Whether to enable preview function @default `true` */
  enablePreview?: boolean;
  /** Whether to enable scrolling */
  enableScroll?: boolean;
  /** Tool display settings. */
  toolbars?: Commands[];
  /** The tool on the right shows the settings. */
  toolbarsMode?: Commands[];
  /** Tool display filter settings. */
  toolbarsFilter?: (tool: Commands, idx: number) => boolean;
  /** Toolbar on bottom */
  toolbarBottom?: boolean;
  /** Option to hide the tool bar. @deprecated The next major version will be deprecated. Please use `showToolbar`. */
  hideToolbar?: boolean;
  /** Option to hide the tool bar. */
  showToolbar?: boolean;
  /** [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview#options-props) options */
  previewProps?: MarkdownPreviewProps;
  /** replace the default `extensions` */
  reExtensions?: ReactCodeMirrorProps['extensions'];
  /** Edit mode and preview mode switching event */
  onPreviewMode?: (isHide: boolean) => void;
}
import React from 'react';
import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
import { MarkdownPreviewProps, MarkdownPreviewRef } from '@uiw/react-markdown-preview';
export * from '@uiw/react-markdown-preview';
export interface ToolBarProps {
  editor: React.RefObject<ReactCodeMirrorRef>;
  preview: React.RefObject<HTMLDivElement>;
  container: React.RefObject<HTMLDivElement>;
  containerEditor: React.RefObject<HTMLDivElement>;
  editorProps: IMarkdownEditor;
}
export interface MarkdownEditorRef {
  editor: React.RefObject<ReactCodeMirrorRef> | null;
  preview?: React.RefObject<MarkdownPreviewRef> | null;
}
export declare type Commands = keyof typeof defaultCommands | ICommand;
export interface IToolBarProps<T = Commands> extends ToolBarProps {
  className?: string;
  editorProps: IMarkdownEditor;
  mode?: boolean;
  prefixCls?: string;
  toolbars?: T[];
  onClick?: (type: string) => void;
}
declare const MarkdownEditor: MarkdownEditorComponent;
declare type MarkdownEditorComponent = React.FC<React.PropsWithRef<IMarkdownEditor>> & {
  Markdown: typeof MarkdownPreview;
};
export default MarkdownEditor;
import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
import { MarkdownPreviewProps, MarkdownPreviewRef } from '@uiw/react-markdown-preview';
export declare type ButtonHandle = (command: ICommand, props: IMarkdownEditor, options: ToolBarProps) => JSX.Element;
export declare type ICommand = {
  icon?: React.ReactElement;
  name?: string;
  keyCommand?: string;
  button?: ButtonHandle | React.ButtonHTMLAttributes<HTMLButtonElement>;
  execute?: (editor: ReactCodeMirrorRef) => void;
};
export declare const defaultCommands: {
  undo: ICommand;
  redo: ICommand;
  bold: ICommand;
  italic: ICommand;
  header: ICommand;
  strike: ICommand;
  underline: ICommand;
  quote: ICommand;
  olist: ICommand;
  ulist: ICommand;
  todo: ICommand;
  link: ICommand;
  image: ICommand;
  code: ICommand;
  codeBlock: ICommand;
  fullscreen: ICommand;
  preview: ICommand;
};
export declare const getCommands: () => ICommand[];
export declare const getModeCommands: () => ICommand[];
export declare const defaultTheme: import("@codemirror/state").Extension;

Development

npm run watch # Listen create type and .tsx files.
npm run start # Preview code example.

npm run doc

Related

Contributors

As always, thanks to our amazing contributors!

Made with action-contributors.

License

Licensed under the MIT License.

react-markdown-editor's People

Contributors

cbschuld avatar dependabot[bot] avatar elydotdev avatar jaywcjlove avatar mehmetsefabalik avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-markdown-editor's Issues

Embedded Image

I tried adding an inline image like this to my markdown, but it doesn't display.

![png tester2](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHoAAABkCAYAAABJhSQPAAAACXBIWXMAAAsTAAALEwEAmpwYAAADf0lEQVR42u3dW2vTYBzH8eeUPDm0adN2adeddNMpo2ObXoypsDvFd+WbEfRSUUHvxIFOEXG7UEFR5xybulO3tU3XpF4JIiJ43Pw/v+8LKP3nQ54nIaTlC2fOXGKIfAKHANAI0AjQCNAI0AjQCNAI0AjQgEaARoBGgEaARoBGgEaARoBGgAY0AjQCNAI0AjQCNAI0AjQCNKARoBGgEaARoNE/T+EQHL4SwXhsCbnrKWvHU3bdV3rHV3rPlXrPkbqppY5tYXUkVx3JZSo4Z4wxkXa7KukmKul2dDvdd+Mk9ltJ7DeTGNAHXFML+Slnu6slnVkpOfm1og5bttC/8lmp4LwtuGhbzGo40t1kFs7ogyjljNV9ZS9V3OB11Su97XUrWLqJFFtcLEdu9vmRTPSq3+vDHk2oli3k66qXWzie7V8r6AIuxogty+/KbvbxydzActmJcNVNrIYW6uloED0ay4/i9opg64GlH4yHgwe57wL6L/YhtN17k4Xh95HT8z99b0D/xBl891Rx5DDuv4D+AzW1kHMThaFnRzOD//McgP5BT0aD6N5UYYzCLID+Th/ztnPzXFSr+ypDZSZAf3MvPF/LVw/7rRKgf6NtX9nXZsvjW1krS3E+QDPGXgz64e2ZngnKMxoPfXeqMPh0NBimPqex0G3FxfXZythKSZdMmNdI6B1XWlcu9J1uauGYMrNx0OuBpS9f7JsxbW6joD+EtnvlfHXaxFVMABnQpJZrk5GNgN51pDJxTzYKuiM5v3q+epoh2tA3zkUn91zpgpkw9P3xfHWp4pZBTBj6bcXNUnwCBeivatlCXpstY1+mDn1nuucYWIlDv+z3cm+qbi9YCUO3FRe3zkZTICUOPV8L+8BJHLruKevJiWAEnMSh5ybDI6AkDr2VUfbLAR/LNnXo+Vo4AEbi0E0t5IshH9DUoRdHggiEBkA/rOWPg5A49GpBeynHD+KRh148lsUjSOrQKWfs2dHMEPiIQ28ElgM6A6Df9Ho50BkA/arfw20VdeiUM7ZW1EXQEYduaIl3uk2A3sjhQswI6PWc7YHNAOjNwAK0CdBbGUAbAb3r4RUbI6BbWtpgMwC6rbgFNgOgv/z1DyIOLdJuF2wGQNud7j7YDIB24qQNNgOgM42kCTYDoPO7+w2wGQAd1gFtBHRxuw1oE6AL2/stsBkA7cVJB2w/32c7r8DNq/e3jAAAAABJRU5ErkJggg==)

You need some special plugin to be able to view it.
Thanks

ResizeObserver loop completed with undelivered notifications

This is my sample code.

App,tsx

import MarkdownEditor from "@uiw/react-markdown-editor";
import { useState } from "react";

function App() {
  const [value, setValue] = useState("***hello***");
  return (
    <div className='App'>
      <MarkdownEditor
        value={value}
        onChange={(value, viewUpdate) => {
          setValue(value);
        }}
        renderPreview={() => <div />}
      />
    </div>
  );
}

export default App;

package.json

{
  "name": "resizeobserver",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.18.39",
    "@types/react": "^18.2.16",
    "@types/react-dom": "^18.2.7",
    "@uiw/react-markdown-editor": "^5.11.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.9.5",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

image

When I run and double click on the top right tile, the program crashes with this error

Uncaught runtime errors:
×
ERROR
ResizeObserver loop limit exceeded
    at handleError (http://localhost:3000/static/js/bundle.js:52748:58)
    at http://localhost:3000/static/js/bundle.js:52767:7

Bookmarks are not working

Headers doesn’t seems to be generating id when rendering as HTML hence the bookmarks are not working, is there any workaround for bookmarks to work?

[@uiw/react-md-editor": "3.0.8"]

Md

Unsafe Component Lifecycles

Hi Kenny,

Thank you for the great work on this. Starting to use it in a project. Curious if you are tinkering with removing the unsafe lifecycles calls (componentWillMount, componentDidMount, componentDidUpdate)? I am happy to take that on if you have not already started the work?

Thanks//cbs

Uncaught Error

I am currently wrapping for use in an internal project

The wrapper is very simple (in its early stages) and shown below

const MarkdownTextarea: FunctionComponent<MarkdownTextareaProps> = ({ invalid, ...props }) => {
    const classes = useStyles();

    return (
        <MarkdownEditor height={400} visible={true} {...props} />
    );
};

We are testing this wrapper using

    const [value, setValue] = useState<string>("# This is a textarea")
    return (<MarkdownTextarea value={value} onChange={action('onChange')} />)

When validating in story book I see the following error which seems to repeat every 500ms.

MarkdownTextarea/Default/error: (5) ["Uncaught TypeError: Cannot read property 'apply' of undefined", "http://localhost:9090/vendors~main.1a2cfcd6df914474ab0d.hot-update.js", 5350, 61, TypeError]
0: "Uncaught TypeError: Cannot read property 'apply' of undefined"
1: "http://localhost:9090/vendors~main.1a2cfcd6df914474ab0d.hot-update.js"
2: 5350
3: 61
4: TypeError

Any guidance and advice in helping to troubleshoot this would be appreciated

How to Insert text to current cursor position using custom toolbar

How can i insert a specific string at the current cursor position using the custom toolbar feature?

Is theme a method to get current cursor position and insert text? thank you!

this is my code, and it doesn't work properly.

please give me some advice, Thank you!

    execute: (mirror: ReactCodeMirrorRef) => {
      const { view, state, editor } = mirror
      if (!view || !state || !editor) {
        return
      }
      // NOTE: how to get current position of cursor?
      const lineInfo = view.state.doc.lineAt(view.state.selection.main.from)
      console.log(lineInfo)
      const insert = `![image title](image url)`
      view.dispatch({
        changes: {
          from: lineInfo.from,
          to: lineInfo.from + insert.length,
          insert,
        },
        selection: { anchor: lineInfo.from },
      })
    },

Dark mode isn't working

I've set data-color-mode="dark" on the root <html> but the editor is still in light mode.

Looking through the source css I don't see any references to the data-color-mode.

How is dark mode supposed to work?
Screen Shot 2022-05-24 at 23 43 25

source code is here is you are interested

v5.11.2 breaks CSS imports

After updating to v5.11.2 CSS imports are broken:
Module not found: Can't resolve '@uiw/react-markdown-editor/markdown-editor.css'

On v5.11.1 we have no issues.

The imports we have on our code are like this:

import '@uiw/react-markdown-editor/markdown-editor.css';
import '@uiw/react-markdown-preview/markdown.css';

Typescript bug on value prop.

I set my project with Webpack-5 and typescript. I got this error first time I rendered the <MDEditor /> without "value" prop.
md

I checked the documentation and looks like "value" prop is the only required prop but I did not get typescript warning. Typescript gives me warning for other packages's required props so ts configuration in my project is correct. I though this might be a bug.

Text is overlapping the preview, when value of editor is reset

I use MarkdownEditor like this:

<MarkdownEditor
  value={this.state.note}
  onBlur={this.updateMarkdown}
  visible={false}
  height={500}
  ref={this.markdownEditor}
/>

When this.state.note is changed (transitioning to undefined and then to a new string value),
the editor text and the preview are updated correctly but longer lines of the editor text will
overlap with the preview.

Markdown Preview hide not works

I want to hide Preview but not works.
toolbarsMode={["fullscreen"]}

But it shows approx 10px of preview on right and preview button is hidden
previewProps={{
style:{display:none}
}}
same result not hiding completely

Scroll editor to the last symbol position

I set focus into the editor using this solution: #189 (comment) . However, as for anchor I use anchor: view.state.doc.length. And if editor contains more text, than its height, in this case I need it to be automatically scrolled to the bottom (and at the same time to the last symbol position). Any ideas how to achieve this? Thank you in advance!

Global CSS import within the package is causing an issue with Next.js

When using this component with Next.js, I am facing this error. Specifically at lines like these.


error - ./node_modules/@uiw/react-markdown-editor/lib/esm/components/CodeMirror/codemirror.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm

Perhaps we can expose an export that is unstyled and one that is styled?

  1. Expose UnstyledComponents
...
export default UnstyledComponent
  1. Expose a module which has styles also imported.
import UnstyledComponent from ...
import styles from ...

export default ...

Switch to fullscreen

Is there a way to know when the user switches from normal to full screen mode?
Thanks

Is there a callback event for switching between edit mode and preview mode?

Is there a callback event for switching between edit mode and preview mode? I found that the toolbar can still be operated to insert data in preview mode, so I need the callback event for mode switching to obtain the current mode status and set the display and hiding of the toolbar based on the transition.

How is preview show by default

  1. When I import the editor as follows, the preview is not show, How to control preview from ts code
  2. Is it possible to only enable preview mode without editing, Instead of using <MarkdownEditor.Markdown />
const [markdown, setMarkdown] = useState("");
<MarkdownEditor
            height="300px"
            value={markdown}
            onChange={(value) => {
              setMarkdown(value);
            }}
          />

能否实现更多功能

  • 编辑器、预览视图同步滚动
  • 隐藏编辑器(全窗口预览)
  • 顶部工具栏 插入表格 、插入表情、上传图片(剪切板图片上传)、上传文件
  • 快捷键支持
  • 更多自定扩展

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @babel/plugin-proposal-private-property-in-object Unavailable

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • peaceiris/actions-gh-pages v4
  • ncipollo/release-action v1
npm
core/package.json
  • @babel/runtime ^7.22.6
  • @codemirror/lang-markdown ^6.0.0
  • @codemirror/language-data ^6.1.0
  • @uiw/codemirror-extensions-events ^4.12.3
  • @uiw/codemirror-themes ^4.12.3
  • @uiw/react-codemirror ^4.12.3
  • @uiw/react-markdown-preview ^5.0.0
  • @testing-library/react ^14.0.0
  • @types/react-test-renderer ^18.0.0
  • react ^18.2.0
  • react-dom ^18.2.0
  • react-test-renderer ^18.2.0
  • @babel/runtime >=7.10.0
  • react >=16.8.0
  • react-dom >=16.8.0
package.json
  • compile-less-cli ^1.8.14
  • husky ^9.0.0
  • lint-staged ^15.0.1
  • lerna ^8.0.0
  • prettier ^3.0.0
  • tsbb ^4.1.14
  • node >=16.0.0
  • typescript ^5.1.3
www/package.json
  • @types/react ^18.2.17
  • @types/react-dom ^18.2.7
  • @uiw/react-markdown-preview-example ^2.0.0
  • react ^18.2.0
  • react-dom ^18.2.0
  • @babel/plugin-proposal-private-property-in-object ^7.21.11
  • @kkt/less-modules ^7.5.1
  • @kkt/scope-plugin-options ^7.5.1
  • kkt ^7.5.1
  • markdown-react-code-preview-loader ^2.1.2
  • source-map-explorer ^2.5.3

  • Check this box to trigger a request for Renovate to run again on this repository

height reduced which window resize

no matter window get larger or smaller, the height reduced always.
browser: chrome (I tried on safari and firefox as well, same issue)

react-markdown2.mov

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

state update using react not working

const [mark, setMark] = useState('Enter Text Here');
const [visible, setVisible] = useState(true);
<div>
    <label htmlFor="body">
        Body:
    </label>
    <MarkdownEditor
        value={mark}
        visible={visible}
        onChange={(value, viewUpdate) => setMark(value)}
        height="500px"
    />
</div>

In the above code, when ever I start typing because of state update, the cursor moves out of the markdown window, so how can i type continuously?

when using react18 ,there is a bug in ‘resetsize’

when i using react18 and using this as a component
const Editorx = ({ file }) => {
<MarkdownEditor value={file.content} onChange={(editor, data, value) => setContent(value)}>
}
than it give me a error
Uncaught TypeError: Cannot read properties of undefined (reading 'setSize')
it really spend me a lot of time to save this problem.and when i useing react under 18 .it works!

Setting tabIndex on MarkdownEditor doesn't work

setting tabIndex attribute / prop on Markdown editor component like this:

              <MarkdownEditor
                value={value}
                tabIndex="0"
                onChange={onChange}
              />

it doesn't set it when rendered inside the app. Setting tabIndex manually in devtools makes it work as expected

How to remove toolbar at all

Thank you for this awesome component! Please tell, how to remove toolbar at all?
image

I tried passing empty array, however right icons (switch to fullscreen and preview) still remain.
<MarkdownEditor value={markdown} onChange={(value, viewUpdate) => setMarkdown(value)} toolbars={[]} />

Allow uploading image

Hi I am using this great library and may I ask if we can have an image command that allows uploading image from local? Suppose we have a server that can we can upload the image to. The button can then receive a callback that return an image_url to be used in the editor like ![description](image_url).

Creates two div with class: CodeMirror cm-s-default

When I implement the basic example in a newly created react app, it creates two separate text fields inside the editor.
This is really weird.
It looks like this:

Toolbar section

| 1 | #this is a text field which can be edited
| 1 | #this is another text field which is also editable

Editor becomes unresponsive when content is long

Try on https://uiwjs.github.io/react-markdown-editor/ with a very long document (Let's say you duplicate the content until it reaches 1000 lines), the editor becomes slower and slower. If you double or triple the lines, it becomes very unresponsive. Type something and it shows up after some seconds.

I tested the same contents on https://codemirror.net/try/?example=Markdown%20code%20block%20highlighting. It does not have the same problem. I guess the issue stays in this library's implementation.

Note that I tested with Preview OFF, plus under an incognito Chrome window.

TypeError: Cannot read properties of undefined (reading 'DEBUG') with ModuleFederation

I'm trying to use this package with the ModuleFederation microfrontend approach.

From a container app, I retrieve a component that uses this package. While testing the component with Storybook in the same project, it works well. However, when I attempt to use the same component, I encounter the following error:

TypeError: Cannot read properties of undefined (reading 'DEBUG')
    at Function.load (webpack://app/./node_modules/debug/src/browser.js?:228:17)
    at setup (webpack://app/./node_modules/debug/src/common.js?:269:33)
    at eval (webpack://app/./node_modules/debug/src/browser.js?:256:91)
    at ./node_modules/debug/src/browser.js (https://localhost:8085/vendors-node_modules_uiw_react-markdown-editor_esm_index_js.js:433:1)
    at __webpack_require__ (https://localhost:8085/componentsFederations.js:340:33)
    at fn (https://localhost:8085/componentsFederations.js:673:21)
    at eval (webpack://app/./node_modules/micromark/dev/lib/create-tokenizer.js?:5:63)
    at ./node_modules/micromark/dev/lib/create-tokenizer.js (https://localhost:8085/vendors-node_modules_uiw_react-markdown-editor_esm_index_js.js:3255:1)
    at __webpack_require__ (https://localhost:8085/componentsFederations.js:340:33)
    at fn (https://localhost:8085/componentsFederations.js:673:21)

I just use:

 <MarkdownEditor
                        height={300}
                        value={text}
                        onChange={(value, viewUpdate) =>
                            onChange('textName', value)
                        }
                        toolbars={[
                            'undo',
                            'redo',
                            'bold',
                            'header',
                            'italic',
                            'underline',
                            'strike',
                            'blockquote',
                            'link',
                        ]}
                        toolbarsMode={['preview']}
                    />

How to avoid increasing width and just have auto line wrapping?

Having the following issue: when number of characters in line is more, than its width - the whole editor is being increased. Any ideas how to make just auto line wrapping? Video demo: https://somup.com/c3jviXUlmF . Component is styled like this. Version 5.2.0

<MarkdownEditor style={{ height: "150px", overflow: "scroll", padding: "8px", }} value={markdown} onChange={(value, viewUpdate) => { setMarkdown(value); }} />

Default code toolbar

Is there any kind of default code toolbar or does it have to be made custom?

If not are their any references I can go off of?

Multiple Errors - CodeMirror plugin crashed + provider is not a function

Hi, first of all thanks for the good work.

I use basic example, app is run with razzle.

const [markdownVal, setMarkdownVal] = useState(code)
  return (
    <MarkdownEditor
      value={markdownVal}
      onChange={(value) => {
        setMarkdownVal(value)
      }}
    />
  )

On load I get error

CodeMirror plugin crashed: TypeError: tags is not iterable
    at HighlightStyle.style (index.js:232:29)
    at highlightTags (index.js:249:33)
    at HighlightBuilder.highlightRange (index.js:297:22)
    at highlightTree (index.js:267:13)
    at TreeHighlighter.buildDeco (index.js:1664:26)
    at new TreeHighlighter (index.js:1646:33)
    at ViewPlugin.create (index.js:1850:42)
    at PluginInstance.update (index.js:1869:44)
    at new EditorView (index.js:6199:20)
    at useCodeMirror.ts:123:29
    at commitHookEffectListMount (react-dom.development.js:23150:26)
    at commitPassiveMountOnFiber (react-dom.development.js:24926:13)
    at commitPassiveMountEffects_complete (react-dom.development.js:24891:9)
    at commitPassiveMountEffects_begin (react-dom.development.js:24878:7)
    at commitPassiveMountEffects (react-dom.development.js:24866:3)
    at flushPassiveEffectsImpl (react-dom.development.js:27039:3)
    at flushPassiveEffects (react-dom.development.js:26984:14)
    at react-dom.development.js:26769:9
    at workLoop (scheduler.development.js:266:34)
    at flushWork (scheduler.development.js:239:14)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:533:21)

which is discussed here https://discuss.codemirror.net/t/highlighting-that-seems-ignored-in-cm6/4320/15

On editor click I get

index.js:2813 Uncaught TypeError: provider is not a function or its return value is not iterable
    at EditorState.languageDataAt (index.js:2813:32)
    at CompletionState.update (index.js:683:19)
    at StateField.update [as updateF] (index.js:819:38)
    at Object.update (index.js:1795:34)
    at EditorState.computeSlot (index.js:2627:94)
    at ensureAddr (index.js:2031:25)
    at new EditorState (index.js:2564:13)
    at EditorState.applyTransaction (index.js:2627:9)
    at get state [as state] (index.js:2278:29)
    at EditorView.update (index.js:6278:24)
    at EditorView._dispatch (index.js:6193:59)
    at EditorView.dispatch (index.js:6259:14)
    at MouseSelection.select (index.js:3590:23)
    at MouseSelection.move (index.js:3571:14)

which is in node_modules/@codemirror/state/dist/index:2811

If I patch these, it will start working, however more errors show up when typing e.g. <div in editor..

Any ideas?

Wrap text in editor

Hello,
I want to wrap text to new line just like vs code.
I have given the fixed height to the editor but didn't find wrapText option

Thanks

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.