|
67 | 67 | console.log(e.stack);
|
68 | 68 | }
|
69 | 69 | },
|
70 |
| -) |
| 70 | + ) |
71 | 71 | .command(
|
72 | 72 | 'bundle [spec]',
|
73 | 73 | 'bundle spec into zero-dependency HTML-file',
|
@@ -112,7 +112,7 @@ yargs
|
112 | 112 | console.log(e.message);
|
113 | 113 | }
|
114 | 114 | },
|
115 |
| -) |
| 115 | + ) |
116 | 116 | .demandCommand()
|
117 | 117 | .options('t', {
|
118 | 118 | alias: 'template',
|
@@ -219,20 +219,20 @@ async function getPageHTML(
|
219 | 219 | redocHTML: `
|
220 | 220 | <div id="redoc">${(ssr && html) || ''}</div>
|
221 | 221 | <script>
|
222 |
| - ${(ssr && `const __redoc_state = ${JSON.stringify(state)};`) || ''} |
223 |
| - |
| 222 | + ${(ssr && `const __redoc_state = ${escapeUnicode(JSON.stringify(state))};`) || ''} |
| 223 | +
|
224 | 224 | var container = document.getElementById('redoc');
|
225 | 225 | Redoc.${
|
226 | 226 | ssr
|
227 | 227 | ? 'hydrate(__redoc_state, container);'
|
228 | 228 | : `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
|
229 |
| - }; |
| 229 | + }; |
230 | 230 |
|
231 | 231 | </script>`,
|
232 | 232 | redocHead: ssr
|
233 | 233 | ? (cdn
|
234 |
| - ? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>' |
235 |
| - : `<script>${redocStandaloneSrc}</script>`) + css |
| 234 | + ? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>' |
| 235 | + : `<script>${redocStandaloneSrc}</script>`) + css |
236 | 236 | : '<script src="redoc.standalone.js"></script>',
|
237 | 237 | title: title,
|
238 | 238 | });
|
@@ -288,3 +288,8 @@ function debounce(callback: Function, time: number) {
|
288 | 288 | function isURL(str: string): boolean {
|
289 | 289 | return /^(https?:)\/\//m.test(str);
|
290 | 290 | }
|
| 291 | + |
| 292 | +// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/ |
| 293 | +function escapeUnicode(str) { |
| 294 | + return str.replace(/\u2028|\u2029/g, m => '\\u202' + (m === '\u2028' ? '8' : '9')); |
| 295 | +} |
0 commit comments