Skip to content

Commit 73ce430

Browse files
committed
Update fetch logic and dist files of docs
1 parent 2956cac commit 73ce430

File tree

7 files changed

+92
-52
lines changed

7 files changed

+92
-52
lines changed

docs/dist/showdowns.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/showdowns.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/showdowns.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import path from 'path';
66

77
// 帮助寻找node_modules里的包
8-
import resolve from '@rollup/plugin-node-resolve';
8+
import nodeResolve from '@rollup/plugin-node-resolve';
99
// rollup 的 babel 插件,ES6转ES5
1010
import babel from '@rollup/plugin-babel';
1111
// 将非ES6语法的包转为ES6可用
@@ -81,18 +81,22 @@ const config = {
8181
},
8282
// 作用:指出应将哪些模块视为外部模块,否则会被打包进最终的代码里
8383
external: [
84+
'@rokt33r/js-sequence-diagrams',
85+
'@viz-js/viz',
8486
'abcjs',
85-
'mermaid',
87+
'echarts',
88+
'flowchart.js',
8689
'katex',
90+
'katex/dist/contrib/auto-render',
91+
'mermaid',
92+
'railroad-diagrams',
8793
'raphael',
88-
'flowchart.js',
89-
'@viz-js/viz',
90-
'wavedrom',
94+
'snapsvg',
95+
'underscore',
9196
'vega',
92-
'vega-lite',
9397
'vega-embed',
94-
'@rokt33r/js-sequence-diagrams',
95-
'katex/dist/contrib/auto-render'
98+
'vega-lite',
99+
'wavedrom'
96100
],
97101
plugins: [
98102
json(),
@@ -134,7 +138,7 @@ if (isFormatCJS) {
134138
exclude: '**/node_modules/**',
135139
babelHelpers: 'bundled'
136140
}),
137-
resolve({
141+
nodeResolve({
138142
browser: true,
139143
preferBuiltins: true,
140144
// 选择module目录传递给解析插件
@@ -156,7 +160,7 @@ if (isMinBuild) {
156160
pure_getters: true,
157161
unsafe: true,
158162
unsafe_comps: true,
159-
drop_console: !isDemoBuild
163+
drop_console: false
160164
}
161165
})
162166
);

src/extensions/showdown-kroki.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,48 @@ function renderKrokiElement(element, config) {
6969
(element.classList.length > 0 ? element.classList[0] : '') +
7070
(!element.className || !diagramClass ? '' : ' ') +
7171
diagramClass;
72-
if (diagramType.length > 0 && typeof window !== 'undefined' && window.fetch) {
72+
if (diagramType.length > 0 && !!window && window.fetch) {
7373
const id = `${diagramType}-${checksum}-` + Date.now() + '-' + Math.floor(Math.random() * 10000);
7474
const imageFormat = config.imageFormat;
7575
const website = 'https://' + config.serverUrl;
7676
const src = `${website}/${diagramType}/${imageFormat}`;
77-
window
78-
.fetch(src, {
77+
try{
78+
window.fetch(src, {
7979
method: 'POST',
8080
body: code,
8181
headers: { Accept: `*/*`, 'Content-Type': 'text/plain; charset=utf-8' }
82-
})
83-
.then(response => {
84-
if (typeof response === 'string') {
85-
return response;
82+
}).then((res) => {
83+
if (typeof res === 'string') {
84+
return res;
8685
}
8786

88-
if (response.ok) {
89-
return response.text();
87+
if (res.ok) {
88+
return res.text();
9089
}
91-
})
92-
.then(svgData => {
93-
const outerHTML = `<div id="${id}" class="${classnames}">${svgData}</div>`;
90+
91+
return new Error(`RequestError: ${res.status}-${res.statusText}`);
92+
}).then((svg) => {
93+
if (typeof svg === 'Error') {
94+
console.log(`kroki to ${imageFormat} of ${diagramType} failed:`, svg.toString());
95+
resolve(false);
96+
return;
97+
}
98+
99+
const outerHTML = `<div id="${id}" class="${classnames}">${svg}</div>`;
94100
element.parentNode.outerHTML = outerHTML;
95101
graphsCache[checksum] = outerHTML;
96102
resolve(true);
103+
}).catch((err) => {
104+
console.log(`kroki to ${imageFormat} of ${diagramType} failed:`, err.toString());
105+
resolve(false);
97106
});
107+
} catch(err) {
108+
console.log(`kroki to ${imageFormat} of ${diagramType} failed:`, err.toString());
109+
resolve(false);
110+
}
111+
return;
98112
}
113+
resolve(false);
99114
});
100115
}
101116

@@ -124,7 +139,7 @@ function showdownKroki(userConfig) {
124139
{
125140
type: 'output',
126141
config: config,
127-
filter: function(obj) {
142+
filter: function (obj) {
128143
const wrapper = obj.wrapper;
129144
if (!wrapper) {
130145
return false;

src/extensions/showdown-plantuml.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,57 @@ function renderPlantumlElement(element, config) {
5454
element.parentNode.outerHTML = `<div id="${id}" class="${name}">${svgData}</div>`;
5555
resolve(true);
5656
});
57-
} else if (typeof window !== 'undefined' && window.fetch && window.dispatchEvent) {
58-
const protocol = window && window.location.protocol;
57+
return;
58+
}
59+
if (!!window && window.fetch) {
60+
const protocol = window.location && window.location.protocol;
5961
const website = (protocol === 'http:' || protocol === 'https:' ? '//' : 'https://') + config.umlWebSite;
6062
const imageExtension = imageFormat !== defaultImageFormat ? `.${imageFormat}` : '';
6163
const uml = plantumlcodec.encodeuml(code);
6264
const src = `${website}/${imageFormat}/${uml}${imageExtension}`;
63-
window
64-
.fetch(src)
65-
.then(response => {
66-
if (typeof response === 'string') {
67-
return response;
68-
}
65+
try {
66+
window
67+
.fetch(src)
68+
.then((res) => {
69+
if (typeof res === 'string') {
70+
return res;
71+
}
72+
73+
if (res.ok) {
74+
return res.text();
75+
}
6976

70-
if (response.ok) {
71-
return response.text();
72-
}
73-
})
74-
.then(svgData => {
75-
element.parentNode.outerHTML = `<div id="${id}" class="${name}">${svgData}</div>`;
76-
resolve(true);
77-
});
77+
return new Error(`RequestError: ${res.status}-${res.statusText}`);
78+
})
79+
.then((svg) => {
80+
if (typeof svg === 'Error') {
81+
console.log('render remote plantuml failed: ', svg.toString());
82+
resolve(false);
83+
return;
84+
}
85+
86+
element.parentNode.outerHTML = `<div id="${id}" class="${name}">${svg}</div>`;
87+
resolve(true);
88+
}).catch((err) => {
89+
console.log('render remote plantuml failed: ', err.toString());
90+
resolve(false);
91+
});
92+
} catch (err) {
93+
console.log('render remote plantuml failed: ', err.toString());
94+
resolve(false);
95+
}
96+
return;
7897
}
79-
} else {
80-
const protocol = window && window.location.protocol;
81-
const website = (protocol === 'http:' || protocol === 'https:' ? '//' : 'https://') + config.umlWebSite;
82-
const imageExtension = imageFormat !== defaultImageFormat ? `.${imageFormat}` : '';
83-
const uml = plantumlcodec.encodeuml(code);
84-
const src = `${website}/${imageFormat}/${uml}${imageExtension}`;
85-
element.parentNode.outerHTML = `<div class="${name}"><img src='${src}' alt=''></img></div>`;
86-
return resolve(true);
98+
resolve(false);
99+
return;
87100
}
101+
const protocol = window && window.location.protocol;
102+
const website = (protocol === 'http:' || protocol === 'https:' ? '//' : 'https://') + config.umlWebSite;
103+
const imageExtension = imageFormat !== defaultImageFormat ? `.${imageFormat}` : '';
104+
const uml = plantumlcodec.encodeuml(code);
105+
const src = `${website}/${imageFormat}/${uml}${imageExtension}`;
106+
element.parentNode.outerHTML = `<div class="${name}"><img src='${src}' alt=''></img></div>`;
107+
return resolve(true);
88108
});
89109
}
90110

@@ -117,7 +137,7 @@ function showdownPlantuml(userConfig) {
117137
{
118138
type: 'output',
119139
config: config,
120-
filter: function(obj) {
140+
filter: function (obj) {
121141
const wrapper = obj.wrapper;
122142
if (!wrapper) {
123143
return false;

src/less/toc.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
width: 100%;
5555
order: -1;
5656
page-break-after: always;
57+
break-after: page;
5758

5859
.toc-view ul li div i:not(.toc-chapter) {
5960
cursor: pointer;
@@ -214,7 +215,7 @@
214215
max-width: 50%;
215216
min-width: 256px;
216217
min-height: 300px;
217-
margin-right: 8px;
218+
margin-right: 12px;
218219
transition: all .3s;
219220
position: fixed;
220221
top: 0;

0 commit comments

Comments
 (0)