GithubHelp home page GithubHelp logo

strapi-wysiwyg-mdxeditor-plugin's Introduction

Strapi plugin wysiwyg

  • This plugin is a WYSIWYG editor for Strapi. It uses the @mdxeditor/editor to provide a rich text editor for Strapi.

  • Allows you to replace default Strapi WYSIWYG editor with a MdxEditor.

blog

MdxEditor:

Home https://mdxeditor.dev/

Live demo https://mdxeditor.dev/editor/demo

Features:

  • Rich text editor
  • Markdown editor
  • Live preview
  • Customizable
  • Keyboard shortcuts
  • Plugins editor.plugins.jsx
  • Media library (now supports only images)
  • Themes
  • Extensions
  • Supports STRAPI media library

Todo

  • Youtube & Vimeo embed video

Setup:

  1. Install the plugin
mkdir -pv ./src/plugins/wysiwyg
cd !$
git clone [email protected]:floatrx/strapi-wysiwyg-mdxeditor-plugin.git
  1. Add the following code to config/plugins.js
export default ({ env }) => ({
  // ...
  wysiwyg: {
    enabled: true,
    resolve: './src/plugins/wysiwyg',
  },
});
  1. Update strapi::security in config/middlewares.js
export default ({ env }) => {
  return [
    'strapi::logger',
    'strapi::errors',
    {
      name: 'strapi::security',
      config: {
        contentSecurityPolicy: {
          useDefaults: true,
          directives: {
            'script-src': ["'self'", "'unsafe-eval'"],
            'frame-src': ['youtube.com', 'www.youtube.com', 'vimeo.com', '*.vimeo.com'],
          }
        }
      }
    }
    // ... other middlewares
  ];
};

Render markdown on client

React-markdown + Tailwind CSS + TW Typography (prose)

Example (React-markdown):

import Markdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';

export type RichTextProps = {
  content?: string;
  className?: string;
};

/**
 * Shared.RichText
 * Supports markdown, gfm, raw html
 *
 * @relation StrapiSharedRichText
 * @param content
 * @param className
 * @constructor
 */
export const RichText = ({ content, className }: RichTextProps) => {
  if (!content) return null;

  return (
    <Markdown className={className} remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeRaw]}>
      {content}
    </Markdown>
  );
};

React-markdown also supports rendering custom components.:

import Markdown from 'react-markdown';
import { Link } from './Link'; // your custom link component
import { Button } from './Button'; // custom button

const customComponents = {
  a: ({ node, className, ...props }) => {
    const isExternalLink = !!props?.href?.match(/^http/im) || 'blank' in props;
    return (
      <Link
        className={cn(className, 'link')}
        target={isExternalLink ? '_blank' : '_self'}
        rel={isExternalLink ? 'noopener nofollow' : 'follow'}
        {...props}
      />
    );
  },
  button: ({ node, ...props }) => <Button {...props} />,
};

export const RichText = (props: RichTextProps) => {
  if (!content) return null;

  return (
    <Markdown components={customComponents} {...props}>
      {content}
    </Markdown>
  );
};

Boilerplate generated by strapi generate:plugin.

Note

Thanks to MDXEditor for the great work.

๐Ÿ‘‹ Regards, floatrx!

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.