forked from Gitlink/forgeplus-react
锚点跳转
This commit is contained in:
parent
68eb499a8c
commit
2129a222e5
|
@ -3888,6 +3888,11 @@
|
|||
"randomfill": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"crypto-js": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/crypto-js/download/crypto-js-4.0.0.tgz",
|
||||
"integrity": "sha1-KQSrJnep0EKFai6i74DekuSjbcw="
|
||||
},
|
||||
"crypto-random-string": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz",
|
||||
|
|
|
@ -27,7 +27,7 @@ if (isDev) {
|
|||
}
|
||||
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
|
||||
window.location.search.indexOf('debug=s') !== -1 ? 'student' :
|
||||
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'student'
|
||||
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'admin'
|
||||
}
|
||||
function clearAllCookie() {
|
||||
cookie.remove('_educoder_session', { path: '/' });
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { useEffect, useRef, useMemo } from 'react'
|
|||
import 'katex/dist/katex.min.css'
|
||||
import marked, { getTocContent, cleanToc, getMathExpressions, resetMathExpressions } from '../common/marked';
|
||||
import 'code-prettify'
|
||||
import dompurify from 'dompurify'
|
||||
import dompurify from 'dompurify';
|
||||
|
||||
import { renderToString } from 'katex'
|
||||
|
||||
|
@ -14,12 +14,14 @@ function _unescape(str) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
export default ({
|
||||
value = '',
|
||||
className,
|
||||
style = {},
|
||||
url
|
||||
}) => {
|
||||
let str = String(value)
|
||||
let str = String(value);
|
||||
|
||||
const html = useMemo(() => {
|
||||
let rs = marked(str)
|
||||
|
@ -36,7 +38,21 @@ export default ({
|
|||
resetMathExpressions()
|
||||
return dompurify.sanitize(rs)
|
||||
|
||||
}, [str])
|
||||
}, [str]);
|
||||
|
||||
// 锚点跳转,链接地址里含#对应的id
|
||||
useEffect(()=>{
|
||||
if(url && url.hash && html){
|
||||
let u = url.hash;
|
||||
if(u){
|
||||
let id = decodeURIComponent(u.split("#")[1]);
|
||||
let ele = document.getElementById(id);
|
||||
if(ele){
|
||||
window.scrollTo(0, ele.offsetTop - window.innerHeight / 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
},[url])
|
||||
|
||||
const el = useRef();
|
||||
function onAncherHandler(e) {
|
||||
|
|
|
@ -116,7 +116,7 @@ function Index(props){
|
|||
:
|
||||
<div style={{padding:"20px 0px"}}>
|
||||
{content ?
|
||||
<RenderHtml className="break_word_comments imageLayerParent" value={content} />
|
||||
<RenderHtml className="break_word_comments imageLayerParent" value={content} url={this.props.history.location}/>
|
||||
:
|
||||
<div>暂无简介~</div>
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ class CoderRootDirectory extends Component {
|
|||
</div>
|
||||
<div className="commonBox-info">
|
||||
{readMeContent[0].content ?
|
||||
<RenderHtml className="break_word_comments imageLayerParent" value={readMeContent[0].content} />
|
||||
<RenderHtml className="break_word_comments imageLayerParent" value={readMeContent[0].content} url={this.props.history.location}/>
|
||||
:
|
||||
<span>暂无~</span>
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ class CoderRootFileDetail extends Component {
|
|||
) : (
|
||||
md && readOnly ?
|
||||
<div className="files-md">
|
||||
<RenderHtml className="file-md imageLayerParent" value={description} />
|
||||
<RenderHtml className="file-md imageLayerParent" value={description} url={this.props.history.location}/>
|
||||
</div>
|
||||
:
|
||||
<Meditor
|
||||
|
|
|
@ -209,7 +209,7 @@ class MessageCount extends Component {
|
|||
};
|
||||
|
||||
commentCtx = (v) => {
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
|
||||
};
|
||||
|
||||
setCopyVisible=(e)=>{
|
||||
|
|
|
@ -182,7 +182,7 @@ class Detail extends Component {
|
|||
};
|
||||
|
||||
commentCtx = (v) => {
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -86,7 +86,7 @@ class children_comments extends Component {
|
|||
};
|
||||
|
||||
commentCtx = (v) => {
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
|
||||
};
|
||||
|
||||
Paginations =()=> {
|
||||
|
|
|
@ -51,7 +51,7 @@ class children_journals extends Component {
|
|||
};
|
||||
|
||||
commentCtx = (v) => {
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
|
||||
};
|
||||
|
||||
Paginations =()=> {
|
||||
|
|
|
@ -263,7 +263,7 @@ class comments extends Component {
|
|||
}
|
||||
|
||||
commentCtx = (v) => {
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
|
||||
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
|
||||
};
|
||||
Paginations = ()=>{
|
||||
const { page, limit, search_count } = this.state;
|
||||
|
|
Loading…
Reference in New Issue