Git Product home page Git Product logo

brilliant-js / brilliant Goto Github PK

View Code? Open in Web Editor NEW
109.0 109.0 14.0 3.56 MB

Brilliant is a WYSIWYG markdown editor with live preview support, based on Draft-js and React, implemented in TypeScript. It's compatible with popular browsers.

Home Page: https://brilliant-js.com

License: MIT License

HTML 0.19% TypeScript 88.28% SCSS 6.96% CSS 3.85% JavaScript 0.71%
draft draft-editor draft-js editor editors markdown markdown-editor markdown-previewer react react-editor react-editor-js react-hooks typescript wysiwyg wysiwyg-editor wysiwyg-html-editor

brilliant's People

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

brilliant's Issues

如何将html的字符串作为初始值

您好!brilliant是我调研期间观感最好的富文本组件,感谢您对社区的贡献!

但有个问题困惑了我,我期望组件能形成html字符串的value/onChange数据流,于是尝试了2种方法:
1)通过draft-js-export-htmldraft-js-import-html进行出入值的转换:

import 'brilliant-editor/dist/index.css';
import './index.scss';

import Brilliant from 'brilliant-editor';
import { EditorState } from 'draft-js';
import { stateToHTML } from 'draft-js-export-html';
import { stateFromHTML } from 'draft-js-import-html';
import _get from 'lodash/get';
import meta from 'meta';
import React from 'react';
import axiosInstance from 'remote/axios';

export interface IMarkdownEditorProps {
  value?: string;
  onChange?: (value?: string) => void;
}

export async function upload(file: FormData) {
  const fileData = file.get('file') as File;
  const { name, size, type, lastModified } = fileData;
  const data: any = await axiosInstance.post('/crm/file/upload', file);
  return {
    id: lastModified + '',
    name,
    type,
    size,
    url: `${meta.staticRootPath}${data.path}`,
  };
}

export default function MarkdownEditor(props: IMarkdownEditorProps) {
  const { value: propsValue = '', onChange } = props;
  const [value, setValue] = React.useState(EditorState.createEmpty());

  React.useEffect(() => {
    setValue(EditorState.createWithContent(stateFromHTML(propsValue)))
  }, [propsValue]);

  function onEditorChange(editorState: EditorState) {
    onChange && onChange(stateToHTML(editorState.getCurrentContent()));
  }

  return (
    <Brilliant
      imgControls
      language="zh"
      value={value}
      onEditorChange={onEditorChange}
      handleImgUpload={upload}
      disableFloatControls
    />
  );
} 

2)通过html-to-draftjsdraftjs-to-html进行出入值的转换:

import 'brilliant-editor/dist/index.css';
import './index.scss';

import Brilliant from 'brilliant-editor';
import { ContentState, convertToRaw, EditorState } from 'draft-js';
import draftToHtml from 'draftjs-to-html';
import htmlToDraft from 'html-to-draftjs';
import _get from 'lodash/get';
import meta from 'meta';
import React from 'react';
import axiosInstance from 'remote/axios';

export interface IMarkdownEditorProps {
  value?: string;
  onChange?: (value?: string) => void;
}

export async function upload(file: FormData) {
  const fileData = file.get('file') as File;
  const { name, size, type, lastModified } = fileData;
  const data: any = await axiosInstance.post('/crm/file/upload', file);
  return {
    id: lastModified + '',
    name,
    type,
    size,
    url: `${meta.staticRootPath}${data.path}`,
  };
}

export default function MarkdownEditor(props: IMarkdownEditorProps) {
  const { value: propsValue = '', onChange } = props;
  const [value, setValue] = React.useState(EditorState.createEmpty());

  React.useEffect(() => {
    const blocksFromHtml = htmlToDraft(propsValue);
    const { contentBlocks, entityMap } = blocksFromHtml;
    const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
    const editorState = EditorState.createWithContent(contentState);
    setValue(editorState);
  }, [propsValue]);

  function onEditorChange(editorState: EditorState) {
    const rawContentState = convertToRaw(editorState.getCurrentContent());
    const markup = draftToHtml(
      rawContentState,
      // hashtagConfig,
      // directional,
      // customEntityTransform
    );
    onChange && onChange(markup);
  }

  return (
    <Brilliant
      imgControls
      language="zh"
      value={value}
      onEditorChange={onEditorChange}
      handleImgUpload={upload}
      disableFloatControls
    />
  );
}

均无法实现初始的html字符串的设置。
期待您的回复。

[solution] ordered list item num displayed as “[object Object]” when export as markdown

Bug found and solution

@brilliant-js

When you decide to export as markdown, you may found the ordered list items are not displayed properly.
【当选择以markdown导出的时候,有序列表的序号可能无法正常显示。】

If you get 【如果导出时显示】

[object Object]. 1111
[object Object]. 2222

instead of 【而不是】

1. 1111
2. 2222

Here is how to fix it.

  1. locate the file PROJECT_DIR\node_modules\brilliant-editor\dist\brilliant-editor.cjs.development.js
  2. locate the line 4712 markdownString += (customStyleItems[type] || StyleItems[type]).open(block, orderedListNumber[block.depth]);
  3. change it to markdownString += (customStyleItems[type] || StyleItems[type]).open(orderedListNumber[block.depth]);

【解决方法如下】

  1. 找到文件: 项目目录\node_modules\brilliant-editor\dist\brilliant-editor.cjs.development.js
  2. 定位第4712行:markdownString += (customStyleItems[type] || StyleItems[type]).open(block, orderedListNumber[block.depth]);
  3. 讲第4712行改为: markdownString += (customStyleItems[type] || StyleItems[type]).open(orderedListNumber[block.depth]);

Hope this post could help you. Happy hacking.

Google Drive app

Please release this as a Google Drive integration. Below is your competition. I would pay $50 (one time) to use Brilliant integrated into Google Drive to open Markdown file in there.

Screen Shot 2021-04-15 at 10 25 06

希望添加的功能

请问可以加一个复制到 markdown 文档到编辑器 从而可以在编辑器实时编辑,并且能生成相应的markdown 文本的功能吗?

editorState.getCurrentContent() convert to markdown.

handlePastedText

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.