diff --git a/public/index.html b/public/index.html index 0cd671ef0..a23396321 100755 --- a/public/index.html +++ b/public/index.html @@ -55,6 +55,14 @@ $('#ie_info').css({ display: 'block' }); $('#root').css({ display: 'none' }); } + window.onload=function(){ + $(".newContainer").delegate("a.anchors","click",function(){ + let h = $(this).offset().top - 180; + $("html,body").animate({scrollTop:h},10); + window.location.hash = $(this).attr("name"); + return false; + }); + } diff --git a/src/common/marked.js b/src/common/marked.js index abfd657a0..674b986c5 100644 --- a/src/common/marked.js +++ b/src/common/marked.js @@ -155,7 +155,8 @@ renderer.heading = function (text, level, raw) { level: level, text: text }) - return '' + text + '' + let id = anchor.replace(/[.,/#!$%^&*;:{}=\-_`~():,。¥;「」|?》《~·【】‘、!]/g,""); + return '' + text + '' } marked.setOptions({ silent: true, diff --git a/src/components/render-html.jsx b/src/components/render-html.jsx index bcebb663a..7f7db76b6 100644 --- a/src/components/render-html.jsx +++ b/src/components/render-html.jsx @@ -1,12 +1,12 @@ 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 'code-prettify'; import dompurify from 'dompurify'; import { renderToString } from 'katex' -const preRegex = /]*>/g +const preRegex = /]*>/g; function _unescape(str) { let div = document.createElement('div') div.innerHTML = str @@ -46,7 +46,7 @@ export default ({ let id = decodeURIComponent(u.split("#")[1]); let ele = document.getElementById(id); if(ele){ - window.scrollTo(0, ele.offsetTop + 120); + window.scrollTo(0, ele.offsetTop); } } } diff --git a/src/forge/Wiki/Index.jsx b/src/forge/Wiki/Index.jsx index f15b19686..2ac1c6326 100644 --- a/src/forge/Wiki/Index.jsx +++ b/src/forge/Wiki/Index.jsx @@ -9,6 +9,7 @@ import { wikiPages, getWiki, deleteWiki } from './api'; import { httpUrl, TokenKey } from './fetch'; import './Index.scss'; import { isArray } from 'lodash'; +import RenderHtml from '../../components/render-html'; const Search = Input.Search; const InputGroup = Input.Group; const { Option } = Select; @@ -271,7 +272,7 @@ export default (props) => { {permission && } -
+ {itemDetail && itemDetail.md_content && }