Skip to content

Commit 107e213

Browse files
committed
Supports codesandbox.io
1 parent 5f98a1a commit 107e213

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

templates/default/introduce/guides/link.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ sort: 7
3838

3939
## 内嵌代码编辑器支持
4040

41-
目前编辑器支持 [codepen.io](https://codepen.io/)[jsfiddle.net](https://jsfiddle.net/)[runjs.cn](http://runjs.cn) 三个网站,其中 runjs.cn 因为不是 `https` 站点,当你的 rdoc 生成的网站是 `https` 浏览器会屏蔽 http 的 runjs.cn 站点嵌入
41+
目前编辑器支持 [codepen.io](https://codepen.io/)[jsfiddle.net](https://jsfiddle.net/)[runjs.cn](http://runjs.cn) 三个网站。
4242

4343
### 编辑器 codepen.io 展示效果
4444

4545
直接将网址 `https://codepen.io/jaywcjlove/pen/ZWJVKy` 贴入 Markdown 中,出如下预览效果。
4646

4747
https://codepen.io/jaywcjlove/pen/ZWJVKy
4848

49+
### 编辑器 codesandbox.io 展示效果
50+
51+
直接将网址 `https://codesandbox.io/s/jlomy0xoo5` 贴入 Markdown 中,出如下预览效果。
52+
53+
https://codesandbox.io/embed/jlomy0xoo5
54+
4955
### 编辑器 jsfiddle.net 展示效果
5056

5157
直接将网址 `https://jsfiddle.net/jaywcjlove/sxx57x6m/` 贴入 Markdown 中,出如下预览效果。
@@ -56,5 +62,7 @@ https://jsfiddle.net/jaywcjlove/sxx57x6m/
5662

5763
直接将网址 `http://runjs.cn/code/yzfkxts2` 贴入 Markdown 中,出如下预览效果。
5864

65+
> runjs.cn 因为不是 `https` 站点,当你的 rdoc 生成的网站如果是 `https` 站点,浏览器会屏蔽 http 的 runjs.cn 站点嵌入
66+
5967
http://runjs.cn/code/yzfkxts2
6068

theme/default/component/Header/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Header extends PureComponent {
2828
const url = item.mdconf && (item.mdconf.github || item.mdconf.url);
2929
if (url) {
3030
return (
31-
<a key={index} target="_blank" href={url}>
31+
<a key={index} target="_blank" rel="noopener noreferrer" href={url}>
3232
{item.mdconf.github && SVGGithub}{item.mdconf.title && <span>{item.mdconf.title}</span>}
3333
</a>
3434
);

theme/default/lib/markdown/Link.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import styles from './Link.less';
44
export default ({ title, href, children }) => {
55
let link = href.replace(/(\/|\/show\/|\/show)$/g, '');
66
if (
7-
/^(http(?:|s):)\/\/(jsfiddle.net|runjs.cn|codepen.io)/.test(link) &&
8-
!/^(https|http):\/\/(jsfiddle.net|runjs.cn|codepen.io)(?:|\/)$/.test(link)
7+
/^(http(?:|s):)\/\/(jsfiddle.net|runjs.cn|codepen.io|codesandbox.io)/.test(link) &&
8+
!/^(https|http):\/\/(jsfiddle.net|runjs.cn|codepen.io|codesandbox.io)(?:|\/)$/.test(link)
99
) {
1010
const regexRunjs = /(https|http):\/\/runjs.cn\/code\/(.*)/gi;
1111
const regexCodepen = /(https|http):\/\/codepen.io\/(.*)\/pen\/(.*)/gi;
12+
const regexCodesandbox = /(https|http):\/\/codesandbox.io\/(s|embed)\/(.*)/gi;
1213
const runjs = regexRunjs.exec(link);
1314
const codepen = regexCodepen.exec(link);
15+
const codesandbox = regexCodesandbox.exec(link);
1416
if (runjs && runjs.length > 2) {
1517
link = `http://sandbox.runjs.cn/show/${runjs[2]}`;
1618
} else if (codepen && codepen.length === 4) {
1719
link = `https://codepen.io/${codepen[2]}/embed/${codepen[3]}?height=400`;
20+
} else if (codesandbox && codesandbox.length === 4) {
21+
link = `https://codesandbox.io/embed/${codesandbox[3]}`;
1822
} else {
1923
link = `${link}/show/`;
2024
}

0 commit comments

Comments
 (0)