Skip to content

Commit 9481b52

Browse files
committed
Improve css for Notebook cells
Signed-off-by: worksofliam <[email protected]>
1 parent 5e3b79e commit 9481b52

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/notebooks/logic/export.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
5252
let executionId = 0;
5353
for (const cell of cells) {
5454
if (token.isCancellationRequested) return;
55-
5655
executionId += 1;
5756

5857
progress.report({ message: `Exporting ${cell.document.languageId.toUpperCase()} cell ${executionId} of ${cells.length}..` });
5958

59+
const cellContents: string[] = [];
60+
6061
switch (cell.document.languageId) {
6162
case `markdown`:
6263
const markdown = cell.document.getText();
63-
cellsHTML.push(converter.makeHtml(markdown));
64+
cellContents.push(converter.makeHtml(markdown));
6465
break;
6566

6667
case `sql`:
@@ -73,7 +74,7 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
7374

7475
({ chartDetail, content } = getStatementDetail(content, eol));
7576

76-
cellsHTML.push(`<pre>${content}</pre>`);
77+
cellContents.push(`<pre>${content}</pre>`);
7778

7879
// Execute the query
7980
const query = selected.job.query(content);
@@ -102,15 +103,15 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
102103
const possibleChart = generateChart(executionId, chartDetail, columns, table, generateChartHTMLEmbedded);
103104
if (possibleChart) {
104105
scripts.push(possibleChart.script);
105-
cellsHTML.push(possibleChart.html);
106+
cellContents.push(possibleChart.html);
106107
fallbackToTable = false;
107108
requiresChartJs = true;
108109
}
109110
}
110111
}
111112

112113
if (fallbackToTable) {
113-
cellsHTML.push([
114+
cellContents.push([
114115
`<table style="width: 100%; margin-left: auto; margin-right: auto;">`,
115116
`<thead>`,
116117
`<tr>`,
@@ -143,7 +144,7 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
143144

144145
case `cl`:
145146
const commandText = cell.document.getText();
146-
cellsHTML.push(`<pre>${commandText}</pre>`);
147+
cellContents.push(`<pre>${commandText}</pre>`);
147148

148149
try {
149150
const command = await connection.runCommand({
@@ -152,15 +153,15 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
152153
});
153154

154155
if (command.stdout) {
155-
cellsHTML.push([
156+
cellContents.push([
156157
`<pre>`,
157158
command.stdout,
158159
`</pre>`
159160
].join(`\n`));
160161
}
161162

162163
if (command.stderr) {
163-
cellsHTML.push([
164+
cellContents.push([
164165
`<pre>`,
165166
command.stderr,
166167
`</pre>`
@@ -177,7 +178,7 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
177178
case `shellscript`:
178179
const shellText = cell.document.getText();
179180

180-
cellsHTML.push(`<pre>${shellText}</pre>`);
181+
cellContents.push(`<pre>${shellText}</pre>`);
181182

182183
try {
183184
const command = await connection.runCommand({
@@ -186,15 +187,15 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
186187
});
187188

188189
if (command.stdout) {
189-
cellsHTML.push([
190+
cellContents.push([
190191
`<pre>`,
191192
command.stdout,
192193
`</pre>`
193194
].join(`\n`));
194195
}
195196

196197
if (command.stderr) {
197-
cellsHTML.push([
198+
cellContents.push([
198199
`<pre>`,
199200
command.stderr,
200201
`</pre>`
@@ -211,7 +212,8 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
211212
break;
212213
}
213214

214-
cellsHTML.push(`<hr />`);
215+
cellsHTML.push(asCell(cellContents.join(`<br />`)));
216+
cellsHTML.push(asCell(`<hr />`));
215217
}
216218

217219
if (cells.length > 0) {
@@ -228,12 +230,12 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
228230
border: 0;
229231
border-top: 1px solid #e8e8e8;
230232
}
231-
tr {
233+
.notebookCell {
232234
padding-top: 1em;
233235
padding-bottom: 1em;
234236
}
235237
@media print {
236-
td {
238+
.notebookCell {
237239
break-inside: avoid;
238240
}
239241
}
@@ -247,7 +249,7 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
247249
<body>
248250
<table style="margin-left: auto; margin-right: auto; width: 60%;">
249251
<tbody style="width: 100%;">
250-
${cellsHTML.map(content => `<tr><td style="padding-top: 0.2em; padding-bottom: 0.2em;">${content}</td></tr>`).join(``)}
252+
${cellsHTML.join(``)}
251253
</tbody>
252254
</table>
253255
</body>
@@ -266,4 +268,8 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
266268
}
267269
}
268270
}
269-
});
271+
});
272+
273+
function asCell(content: string) {
274+
return `<tr><td class="notebookCell" style="padding-top: 0.2em; padding-bottom: 0.2em;">${content}</td></tr>`;
275+
}

0 commit comments

Comments
 (0)