|
1 | 1 | import { AriaTabs } from './aria-tabs'; |
2 | | -import { SuperPlayground } from './super-playground' |
| 2 | +import { SuperPlayground } from './super-playground'; |
3 | 3 |
|
4 | 4 | const preNodes = document.querySelectorAll('pre:has(> code.language-mdtest-spq)'); |
5 | 5 | for (const [i, pre] of preNodes.entries()) { |
6 | | - const codeNode = pre.querySelector('code') |
7 | | - const attributes = Array.from(codeNode.classList) |
| 6 | + const codeNode = pre.querySelector('code'); |
| 7 | + |
| 8 | + // Matches one or more "#"-prefixed lines. |
| 9 | + const sectionSeparatorRE = /(?m:^#.*\n)+/; |
| 10 | + const sections = codeNode.innerText.split(sectionSeparatorRE); |
| 11 | + // Ignore sections[0], which should be empty. |
| 12 | + if (sections.length != 4) { |
| 13 | + continue; |
| 14 | + } |
| 15 | + const spq = sections[1].trim(); |
| 16 | + const input = sections[2].trim(); |
| 17 | + const expected = sections[3].trim(); |
| 18 | + |
| 19 | + let attributes = Array.from(codeNode.classList) |
8 | 20 | .filter((c) => c.match(/^{.*}$/)) |
9 | 21 | .map((c) => c.slice(1, -1)) |
10 | | - .join(' ') |
| 22 | + .join(' '); |
| 23 | + if (input.length === 0) { |
| 24 | + attributes += 'data-layout="no-input"'; |
| 25 | + } |
| 26 | + |
11 | 27 | const html = ` |
12 | 28 | <article class="super-example"> |
13 | 29 | <nav role="tablist"> |
@@ -63,23 +79,17 @@ for (const [i, pre] of preNodes.entries()) { |
63 | 79 | const tablist = node.querySelector('[role="tablist"]'); |
64 | 80 | AriaTabs.setup(tablist); |
65 | 81 |
|
66 | | - // Matches one or more "#"-prefixed lines. |
67 | | - const sectionSeparatorRE = /(?m:^#.*\n)+/; |
68 | | - const sections = codeNode.innerText.split(sectionSeparatorRE); |
69 | | - // Ignore sections[0], which should be empty. |
70 | | - if (sections.length != 4) { |
71 | | - continue; |
72 | | - } |
73 | | - const spq = sections[1].trim(); |
74 | | - const input = sections[2].trim(); |
75 | | - const expected = sections[3].trim(); |
76 | 82 | node.querySelector('.super-playground .query code').textContent = spq; |
77 | 83 | node.querySelector('.super-playground .input code').textContent = input; |
78 | 84 | node.querySelector('.super-playground .result code').textContent = expected; |
79 | 85 |
|
80 | 86 | const commandCode = node.querySelector('.super-command code') |
81 | 87 | SuperPlayground.setup(node, (query, input) => { |
82 | | - commandCode.textContent = `echo '${input}' \\\n| super -s -c '${query}' -` |
| 88 | + let command = `super -s -c '${query}'`; |
| 89 | + if (input.length > 0) { |
| 90 | + command = `echo '${input}' \\\n| ${command} -`; |
| 91 | + } |
| 92 | + commandCode.textContent = command; |
83 | 93 | }); |
84 | 94 |
|
85 | 95 | // Prevent keydown from bubbling up to book.js listeners. |
|
0 commit comments