查看md文件时用md编辑器渲染

This commit is contained in:
caishi 2020-07-02 16:41:06 +08:00
parent 07df361102
commit 09b05a1f3d
4 changed files with 35 additions and 5 deletions

View File

@ -46,8 +46,9 @@ class CoderRootDirectory extends Component {
chooseType:undefined,
tags_count:undefined,
commits_count:undefined,
branches_count:undefined
branches_count:undefined,
md:false
}
}
changeAddress = (address) => {
@ -254,12 +255,21 @@ class CoderRootDirectory extends Component {
};
// 点击跳转到子目录
goToSubRoot=(path,type)=>{
goToSubRoot=(path,type,filename)=>{
this.setState({
chooseType:type
})
const { projectsId } = this.props.match.params;
this.props.history.push(`/projects/${projectsId}/coders?url=${path}`);
if(filename.substring(filename.length - 3) === ".md"){
this.setState({
md:true
})
}else{
this.setState({
md:false
})
}
};
// readme文件内容
@ -348,7 +358,7 @@ class CoderRootDirectory extends Component {
dataIndex: 'name',
width:"30%",
render: (text,item) => (
<a onClick={()=>this.goToSubRoot(item.path,item.type)} className="ml12 task-hide" style={{ display: "block", maxWidth: "345px" }}>
<a onClick={()=>this.goToSubRoot(item.path,item.type,text)} className="ml12 task-hide" style={{ display: "block", maxWidth: "345px" }}>
<i className={ item.type === "file" ? "iconfont icon-wenjia font-15 color-green-file mr5":"iconfont icon-wenjianjia1 color-green-file font-15 mr5"}></i>{text}
</a>
),

View File

@ -3,6 +3,9 @@ import { Popconfirm, Select } from "antd";
import "./list.css";
import axios from "axios";
import Meditor from "../Newfile/m_editor";
import MDEditor from "../../modules/tpm/challengesnew/tpm-md-editor";
import RenderHtml from "../../components/render-html";
function bytesToSize(bytes) {
if (bytes === 0) return "0 B";
@ -18,6 +21,7 @@ class CoderRootFileDetail extends Component {
value: undefined,
language: undefined,
languages: undefined,
description:props.detail.content
};
}
@ -146,6 +150,12 @@ class CoderRootFileDetail extends Component {
});
};
onContentChange = (value) => {
this.setState({
description: value,
});
};
render() {
const {
readOnly,
@ -153,8 +163,9 @@ class CoderRootFileDetail extends Component {
current_user,
isManager,
isDeveloper,
md
} = this.props;
const { language, languages } = this.state;
const { language, languages , description } = this.state;
let flag = current_user && current_user.login && (isManager || isDeveloper);
const Option = Select.Option;
@ -233,6 +244,11 @@ class CoderRootFileDetail extends Component {
</a>
</div>
) : (
md && readOnly ?
<div className="files-md">
<RenderHtml className="file-md" value={description} />
</div>
:
<Meditor
{...this.props}
{...this.state}

View File

@ -162,7 +162,7 @@ class Detail extends Component {
getProject = (num) => {
const name = window.location.hostname === "localhost" ? "testforgeplus.trustie.net":window.location.hostname;
console.log(`ws:${name}/cable`);
console.log(`wss:${name}/cable`);
const { projectsId } = this.props.match.params;
const url = `/projects/${projectsId}/simple.json`;
axios.get(url).then((result) => {

View File

@ -266,6 +266,10 @@
/* color: #1C91FF !important; */
background: rgba(255,255,255,0.5);
}
.files-md{
border:1px solid #eee;
padding:20px;
}
/* 详情-代码 */
.branch-wrapper{
border:1px solid #eee;