forked from Gitlink/forgeplus-react
antd 影响的样式
This commit is contained in:
parent
d4957c8c9c
commit
e5927913f8
|
@ -1,30 +1,30 @@
|
|||
import React, { useEffect, useRef } from 'react'
|
||||
import 'katex/dist/katex.min.css';
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import "katex/dist/katex.min.css";
|
||||
|
||||
import marked, { getTocContent, cleanToc } from '../common/marked'
|
||||
import marked, { getTocContent, cleanToc } from "../common/marked";
|
||||
|
||||
let preRegex = /<pre[^>]*>/g
|
||||
let preRegex = /<pre[^>]*>/g;
|
||||
|
||||
export default ({ value = '', is_md = true, className, style = {} }) => {
|
||||
let str = String(value)
|
||||
let html = is_md ? marked(str) : value
|
||||
export default ({ value = "", is_md = true, className, style = {} }) => {
|
||||
let str = String(value);
|
||||
let html = is_md ? marked(str) : value;
|
||||
if (str.match(/\[TOC\]/)) {
|
||||
html = html.replace("<p>[TOC]</p>", getTocContent())
|
||||
cleanToc()
|
||||
html = html.replace("<p>[TOC]</p>", getTocContent());
|
||||
cleanToc();
|
||||
}
|
||||
|
||||
html = html.replace(/▁/g, "▁▁▁")
|
||||
const el = useRef()
|
||||
html = html.replace(/▁/g, "▁▁▁");
|
||||
const el = useRef();
|
||||
|
||||
function onAncherHandler(e) {
|
||||
let target = e.target
|
||||
if (target.tagName.toUpperCase() === 'A') {
|
||||
let ancher = target.getAttribute('href')
|
||||
if (ancher.startsWith('#')) {
|
||||
e.preventDefault()
|
||||
let viewEl = document.getElementById(ancher.replace('#', ''))
|
||||
let target = e.target;
|
||||
if (target.tagName.toUpperCase() === "A") {
|
||||
let ancher = target.getAttribute("href");
|
||||
if (ancher.startsWith("#")) {
|
||||
e.preventDefault();
|
||||
let viewEl = document.getElementById(ancher.replace("#", ""));
|
||||
if (viewEl) {
|
||||
viewEl.parentNode.scrollTop = viewEl.offsetTop
|
||||
viewEl.parentNode.scrollTop = viewEl.offsetTop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,23 @@ export default ({ value = '', is_md = true, className, style = {} }) => {
|
|||
useEffect(() => {
|
||||
if (el.current && html) {
|
||||
if (html.match(preRegex)) {
|
||||
window.PR.prettyPrint()
|
||||
window.PR.prettyPrint();
|
||||
}
|
||||
}
|
||||
if (el.current) {
|
||||
el.current.addEventListener('click', onAncherHandler)
|
||||
el.current.addEventListener("click", onAncherHandler);
|
||||
return () => {
|
||||
el.current.removeEventListener('click', onAncherHandler)
|
||||
el.current.removeEventListener("click", onAncherHandler);
|
||||
};
|
||||
}
|
||||
}
|
||||
}, [html, el.current, onAncherHandler])
|
||||
}, [html, el.current, onAncherHandler]);
|
||||
|
||||
return (<div ref={el} style={style} className={`${className ? className : ''} markdown-body`} dangerouslySetInnerHTML={{ __html: html }}></div>)
|
||||
}
|
||||
return (
|
||||
<div
|
||||
ref={el}
|
||||
style={style}
|
||||
className={`${className ? className : ""} markdown-body`}
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
></div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
ul,ol,dl{
|
||||
margin-bottom: 0px!important;
|
||||
}
|
||||
.newMain{
|
||||
background-color: #fff;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue