antd 影响的样式

This commit is contained in:
caishi 2020-05-09 13:59:24 +08:00
parent d4957c8c9c
commit e5927913f8
4 changed files with 38 additions and 28 deletions

View File

@ -194,4 +194,4 @@
"webpack": "^4.42.1",
"webpack-bundle-analyzer": "^3.7.0"
}
}
}

View File

@ -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>
);
};

View File

@ -1,3 +1,6 @@
ul,ol,dl{
margin-bottom: 0px!important;
}
.newMain{
background-color: #fff;
}

View File

@ -252,8 +252,8 @@ export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, cla
}
}
}, [
editorInstance, resizeBarEl
])
editorInstance, resizeBarEl
])
return (
<Fragment>