0.1.3 • Published 2 years ago

for-editor-markdown v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

for-editor-markdown

based on for-editor

Install

npm install for-editor-markdown

Use

import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import Editor from 'for-editor'

class App extends Component {
  constructor() {
    super()
    this.state = {
      value: ''
    }
  }

  handleChange(value) {
    this.setState({
      value
    })
  }

  render() {
    const { value } = this.state
    return <Editor value={value} onChange={() => this.handleChange()} />
  }
}

ReactDOM.render(<App />, document.getElementById('root'))

Api

props

nametypedefaultdescription
valueString-value
languageStringpt-BRLanguage switch, pt-BR: Simplified Chinese, en: English
placeholderStringBegin editing...The default prompt text when the textarea is empty
lineNumBooleantrueShow lineNum
styleObject-editor styles
heightString600pxeditor height
previewBooleanfalsepreview switch
expandBooleanfalsefullscreen switch
subfieldBooleanfalsetrue: Double columns - Edit preview same screen(notice: preview: true), Single Columns - otherwise not
toolbarObjectAs in the following exampletoolbars
/*
  The default toolbar properties are all true,
  You can customize the object to cover them.
  eg: {
    h1: true,
    code: true,
    preview: true,
  }
  At this point, the toolbar only displays the three function keys.
  notice: Toolbar will be hidden when empty object.
 */

toolbar: {
  h1: true,
  h2: true,
  h3: true,
  h4: true,
  img: true,
  link: true,
  code: true,
  preview: true,
  expand: true,
  /* v0.0.9 */
  undo: true,
  redo: true,
  save: true,
  /* v0.2.3 */
  subfield: true
}

events

nameparamsdefaultdescription
onChangeString: value-Edit area change callback event
onSaveString: value-Ctrl+s and click save button callback event
addImgFile: file-upload image callback event
upload image
class App extends Component {
  constructor() {
    super()
    this.state = {
      value: ''
    }
    this.$vm = React.createRef()
  }

  handleChange(value) {
    this.setState({
      value
    })
  }

  addImg($file) {
    this.$vm.current.$img2Url($file.name, 'file_url')
    console.log($file)
  }

  render() {
    const { value } = this.state

    return (
      <Editor
        ref={this.$vm}
        value={value}
        addImg={($file) => this.addImg($file)}
        onChange={(value) => this.handleChange(value)}
      />
    )
  }
}

hot key

namedescription
tabtwo space
ctrl+ssave
ctrl+zundo
ctrl+yredo

Update

Licence

for-editor-markdown is MIT Licence.

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago