Skip to content

Commit ced2b2d

Browse files
committed
Merge branch 'feature/zhihu-formula' into develop
2 parents 78f164d + 70551b4 commit ced2b2d

File tree

14 files changed

+218
-153
lines changed

14 files changed

+218
-153
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
## 简介
99

1010
- 支持自定义样式的 Markdown 编辑器
11-
- 支持微信公众号排版
12-
- 支持开源中国、知乎、稀土掘金、博客园和 CSDN 等一系列平台
13-
- 内容和自定义样式浏览器中实时保存
14-
- 支持上传图片、脚注、公式
11+
- 支持微信公众号、知乎、开源中国、稀土掘金、博客园和 CSDN 等一系列平台
12+
- 更多用户和开发者文档请参考 [Markdown Nice Docs](https://docs.mdnice.com/)
1513
- 欢迎[在线使用](https://mdnice.com/)
1614

1715
## 示例
@@ -65,10 +63,6 @@ function App() {
6563
export default App;
6664
```
6765

68-
## 更多文档
69-
70-
更多用户和开发者文档请参考 [Markdown Nice Docs](https://docs.mdnice.com/)
71-
7266
## 关于
7367

7468
mdnice 社区组建了**微信用户群**,欢迎反馈意见和公众号大佬们一起交流,关注公众号回复「排版」拉你入群。

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
"markdown-it-implicit-figures": "^0.9.0",
3535
"markdown-it-katex": "^2.0.3",
3636
"markdown-it-ruby": "^0.1.1",
37-
"markdown-it-sub": "^1.0.0",
38-
"markdown-it-sup": "^1.0.0",
3937
"markdown-it-table-of-contents": "^0.4.4",
4038
"mathjax": "^3.0.0",
4139
"mobx": "^5.9.0",

src/App.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import StyleEditor from "./layout/StyleEditor";
1111
import "./App.css";
1212
import "./utils/mdMirror.css";
1313

14-
import {LAYOUT_ID} from "./utils/constant";
14+
import {LAYOUT_ID, BOX_ID} from "./utils/constant";
1515
import {markdownParser, markdownParserWechat, updateMathjax} from "./utils/helper";
1616
import pluginCenter from "./utils/pluginCenter";
1717
import appContext from "./utils/appContext";
@@ -42,24 +42,16 @@ class App extends Component {
4242
options: {
4343
renderActions: {
4444
addMenu: [0, "", ""],
45-
},
46-
},
47-
startup: {
48-
ready: () => {
49-
window.MathJax.startup.defaultReady();
50-
window.MathJax.startup.promise.then(() => {
51-
const element = document.getElementById(LAYOUT_ID);
52-
let html = element.innerHTML;
53-
html = html.replace(
54-
/<mjx-container.+?display.+?>(.+?)<\/mjx-container>/g,
55-
'<section class="block-equation">$1</section>',
56-
);
57-
html = html.replace(
58-
/<mjx-container.+?>(.+?)<\/mjx-container>/g,
59-
'<span class="inline-equation">$1</span>',
60-
);
61-
element.innerHTML = html;
62-
});
45+
addContainer: [
46+
190,
47+
(doc) => {
48+
for (const math of doc.math) {
49+
const cls = math.display ? "block-equation" : "inline-equation";
50+
math.typesetRoot.className = cls;
51+
math.typesetRoot.setAttribute("data", math.math);
52+
}
53+
},
54+
],
6355
},
6456
},
6557
};
@@ -202,7 +194,7 @@ class App extends Component {
202194
</div>
203195
<div id="marked-text" className="text-box" onMouseOver={(e) => this.setCurrentIndex(2, e)}>
204196
<div
205-
id="wx-box"
197+
id={BOX_ID}
206198
className="wx-box"
207199
onScroll={this.handleScroll}
208200
style={{width: previewType === "pc" ? "100%" : 375}}

src/Lib.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, {Component} from "react";
22
import PropTypes from "prop-types";
3+
import {Result} from "antd";
4+
import {Provider} from "mobx-react";
5+
36
import "./index.css";
47

58
import App from "./App";
69

7-
import {Provider} from "mobx-react";
810
import content from "./store/content";
911
import userInfo from "./store/userInfo";
1012
import navbar from "./store/navbar";
@@ -13,14 +15,27 @@ import imageHosting from "./store/imageHosting";
1315

1416
import {isPC} from "./utils/helper";
1517
import appContext from "./utils/appContext";
16-
import {Result} from "antd";
1718
import SvgIcon from "./icon";
18-
import {solveMath, solveHtml} from "./utils/converter";
19+
import {solveWeChatMath, solveZhihuMath, solveHtml} from "./utils/converter";
20+
import {LAYOUT_ID} from "./utils/constant";
1921

2022
class Lib extends Component {
21-
getHtml() {
22-
solveMath();
23-
return solveHtml();
23+
getWeChatHtml() {
24+
const layout = document.getElementById(LAYOUT_ID); // 保护现场
25+
const html = layout.innerHTML;
26+
solveWeChatMath();
27+
const res = solveHtml();
28+
layout.innerHTML = html; // 恢复现场
29+
return res;
30+
}
31+
32+
getZhihuHtml() {
33+
const layout = document.getElementById(LAYOUT_ID); // 保护现场
34+
const html = layout.innerHTML;
35+
solveZhihuMath();
36+
const res = solveHtml();
37+
layout.innerHTML = html; // 恢复现场
38+
return res;
2439
}
2540

2641
render() {

src/component/Copy.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.nice-copy {
2+
height: 30px;
3+
}
4+
5+
.nice-copy button {
6+
height: 30px;
7+
}

src/component/Copy.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, {Component} from "react";
22
import {observer, inject} from "mobx-react";
3-
import {Button, message, ConfigProvider} from "antd";
3+
import {message, ConfigProvider, Dropdown, Icon, Menu} from "antd";
44

5-
import {solveMath, solveHtml, copySafari} from "../utils/converter";
5+
import {solveWeChatMath, solveZhihuMath, solveHtml, copySafari} from "../utils/converter";
6+
import {LAYOUT_ID} from "../utils/constant";
7+
import "./Copy.css";
68

79
@inject("content")
810
@inject("navbar")
@@ -13,27 +15,49 @@ class Copy extends Component {
1315
constructor(props) {
1416
super(props);
1517
this.html = "";
16-
this.state = {
17-
loading: false,
18-
};
1918
}
2019

21-
copy = () => {
22-
this.setState({loading: true});
23-
solveMath();
20+
copyWechat = () => {
21+
const layout = document.getElementById(LAYOUT_ID); // 保护现场
22+
const html = layout.innerHTML;
23+
solveWeChatMath();
2424
this.html = solveHtml();
25-
// FIXED: safari 复制问题
2625
copySafari(this.html);
2726
message.success("已复制,请到微信公众平台粘贴");
28-
this.setState({loading: false});
27+
layout.innerHTML = html; // 恢复现场
28+
};
29+
30+
copyZhihu = () => {
31+
const layout = document.getElementById(LAYOUT_ID); // 保护现场
32+
const html = layout.innerHTML;
33+
solveZhihuMath();
34+
this.html = solveHtml();
35+
copySafari(this.html);
36+
message.success("已复制,请到知乎粘贴");
37+
layout.innerHTML = html; // 恢复现场
2938
};
3039

3140
render() {
41+
const menu = (
42+
<Menu>
43+
<div style={style.menuItem}>
44+
<div role="button" style={style.themeItem} onClick={this.copyZhihu} onKeyDown={this.copyZhihu} tabIndex="0">
45+
复制到知乎
46+
</div>
47+
</div>
48+
</Menu>
49+
);
3250
return (
3351
<ConfigProvider autoInsertSpaceInButton={false}>
34-
<Button type="primary" style={style.btnHeight} onClick={this.copy} loading={this.state.loading}>
52+
<Dropdown.Button
53+
onClick={this.copyWechat}
54+
overlay={menu}
55+
icon={<Icon type="more" style={style.iconSize} />}
56+
className="nice-copy"
57+
type="primary"
58+
>
3559
复制
36-
</Button>
60+
</Dropdown.Button>
3761
</ConfigProvider>
3862
);
3963
}
@@ -52,6 +76,27 @@ const style = {
5276
close: {
5377
padding: 0,
5478
},
79+
format: {
80+
marginRight: 8,
81+
},
82+
themeItem: {
83+
display: "flex",
84+
justifyContent: "space-between",
85+
},
86+
themeItemAuthor: {
87+
color: "gray",
88+
},
89+
menuItem: {
90+
clear: "both",
91+
margin: 0,
92+
padding: "5px 12px",
93+
color: "rgba(0, 0, 0, 0.65)",
94+
fontWeight: "normal",
95+
fontSize: "14px",
96+
lineHeight: "22px",
97+
whiteSpace: "nowrap",
98+
cursor: "pointer",
99+
},
55100
};
56101

57102
export default Copy;

src/component/Dialog/AboutDialog.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class AboutDialog extends Component {
5252
</h3>
5353

5454
<p style={style.lineHeight}>支持自定义样式的 Markdown 编辑器;</p>
55-
<p style={style.lineHeight}>支持微信公众号排版;</p>
56-
<p style={style.lineHeight}>支持开源中国、知乎、掘金、博客园和CSDN等平台;</p>
55+
<p style={style.lineHeight}>支持微信公众号、开源中国、知乎、掘金、博客园和CSDN等平台;</p>
5756
<h3 style={style.headerMargin}>我们</h3>
5857
<p style={style.lineHeight}>
5958
如果你喜欢我们的工具,欢迎关注

src/component/ImageHosting/AliOSS.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ class AliOSS extends Component {
7575
<Form.Item label="提示" style={style.formItem}>
7676
<span>配置好图床信息后请在右上角进行切换</span>
7777
<br />
78-
<a rel="noopener noreferrer" target="_blank" href="https://mp.weixin.qq.com/s/QPsOUkLCsvhqSicTOGaHJg">
78+
<a
79+
rel="noopener noreferrer"
80+
target="_blank"
81+
href="https://docs.mdnice.com/#/%E9%98%BF%E9%87%8C%E4%BA%91%E5%9B%BE%E5%BA%8A%E6%90%AD%E5%BB%BA"
82+
>
7983
阿里云图床配置文档
8084
</a>
8185
</Form.Item>

src/component/ImageHosting/QiniuOSS.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ class QiniuOSS extends Component {
103103
<Form.Item label="提示" style={style.formItem}>
104104
<span>配置好图床信息后请在右上角进行切换</span>
105105
<br />
106-
<a rel="noopener noreferrer" target="_blank" href="https://mp.weixin.qq.com/s/_ytSpvKnzEVx0l_LONdnHg">
106+
<a
107+
rel="noopener noreferrer"
108+
target="_blank"
109+
href="https://docs.mdnice.com/#/%E4%B8%83%E7%89%9B%E4%BA%91%E5%9B%BE%E5%BA%8A%E6%90%AD%E5%BB%BA"
110+
>
107111
七牛云图床配置文档
108112
</a>
109113
</Form.Item>

0 commit comments

Comments
 (0)