react实现markdown

参考:https://blog.csdn.net/Jack_lzx/article/details/118495763

参考:https://blog.csdn.net/m0_48474585/article/details/119742984

0. 示例

用react实现markdown编辑器

1.基本布局及样式

    <>
      <div className='tf_editor_header'>
        头部:放一些编辑工具
      div>
      <div className='tf_editor'>
        <div className='edit'>
			左边:编辑区域
		div>
        <div className='show'>
  			右边:展示区域
        div>
      div>
    
.tf_editor_header{
  height: 60px;
  width: 100%;
  background-color: #fff;
  border-bottom:1px solid  rgba(0,0,0,.1);
}

.tf_editor{
  display: flex;
  flex-direction: row;
  height: calc(100vh - 60px);
  width: 100%;

  .edit{
    padding: 0.8rem;
    flex: 1;
    background-color: #f5f5f5;
    max-width: 50vw;
    box-sizing: border-box;
    border-right: 1px solid  rgba(0,0,0,.1);
  }

  .show{
    padding: 0.8rem;
    flex: 1;
    background-color: #fff;
    max-width: 50vw;
    box-sizing: border-box;
  }
}

2.编辑区域

  import _ from 'lodash';

  const [content, setContent] = useState('')
  const onEditChange = (e) => { 
    const curContent = e.target.value
    setContent(curContent)
  }