uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.13k stars 155 forks source link

Changing theme #253

Open Lucjus opened 3 years ago

Lucjus commented 3 years ago

How can I change white default gh theme to a theme of my own choice? Is there any other way than overwriting css classes one by one?

jaywcjlove commented 3 years ago

I have not customized other themes, and there is no other way. @Lucjus

sametweb commented 2 years ago

If you are talking about the code block themes in preview, here is the way:

<MDEditor
  previewOptions={{ components: CodeBlock }}
  // other props
/>

CodeBlock.js

import {PrismAsync as SyntaxHighlighter} from 'react-syntax-highlighter'
import {vscDarkPlus} from 'react-syntax-highlighter/dist/cjs/styles/prism'

const CodeBlock = {
  code({children, className, ...props}) {
    let language = 'jsx'
    if (className) {
      language = className.split('-')[1]
    }

    return (
      <SyntaxHighlighter
        wrapLines
        wrapLongLines
        showLineNumbers
        style={vscDarkPlus}
        PreTag='div'
        language={language}
        {...props}>
        {String(children).replace(/\n$/, '')}
        </SyntaxHighlighter>
    )
    },
}

export default CodeBlock
Lucjus commented 2 years ago

@sametweb That was it! Thank You!

michaelnicol commented 5 months ago

I need to use light theme for the website I am working on, and it's been an absolute pain dealing with the styling of the markdown editor. I used some CSS to target the components of the editor to make it light theme.

The problem is that I can't make the bolded text black instead of blue in the editor. Styles have no effect on the colors or font sizes of text in the editor. It's permanently stuck at 16 px font size, which is too small for my clients to read.

Because of this simple issue, I now have to find a different library.