Skip to content

Commit e8fac9e

Browse files
authored
Merge pull request #8208 from sagemathinc/fix-quarto-new-file
quarto fixes
2 parents 3ec8f19 + eb6def8 commit e8fac9e

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

src/packages/frontend/frame-editors/qmd-editor/actions.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ const custom_pdf_error_message: string = `
2828
No PDF file has been generated.
2929
`;
3030

31+
const MINIMAL = `---
32+
title: "Title"
33+
---
34+
35+
## Test
36+
37+
Example plot
38+
39+
\`\`\`{r}
40+
plot(rnorm(100))
41+
\`\`\`
42+
`;
43+
3144
export class Actions extends MarkdownActions {
3245
private _last_qmd_hash: number | undefined = undefined;
3346
private is_building: boolean = false;
@@ -40,6 +53,10 @@ export class Actions extends MarkdownActions {
4053
this._syncstring.once("ready", this._init_qmd_converter.bind(this));
4154
this._check_produced_files();
4255
this.setState({ custom_pdf_error_message });
56+
this._syncstring.on(
57+
"change",
58+
debounce(this.ensureNonempty.bind(this), 1500),
59+
);
4360
}
4461
}
4562

@@ -224,4 +241,11 @@ export class Actions extends MarkdownActions {
224241

225242
// Never delete trailing whitespace for markdown files.
226243
delete_trailing_whitespace(): void {}
244+
245+
private ensureNonempty() {
246+
if (this.store && !this.store.get("value")?.trim()) {
247+
this.set_value(MINIMAL);
248+
this.build();
249+
}
250+
}
227251
}

src/packages/frontend/project/new/consts.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IconName } from "@cocalc/frontend/components";
2+
import { file_associations } from "@cocalc/frontend/file-associations";
23

3-
export const NEW_FILETYPE_ICONS: { [ext: string]: IconName } = {
4+
export const NEW_FILETYPE_ICONS = {
45
"/": "folder-open",
56
ipynb: "jupyter",
67
sagews: "sagemath-bold",
@@ -16,12 +17,13 @@ export const NEW_FILETYPE_ICONS: { [ext: string]: IconName } = {
1617
server: "server",
1718
course: "graduation-cap",
1819
time: "stopwatch",
20+
qmd: file_associations.qmd.icon,
1921
rmd: "r",
2022
py: "python",
2123
jl: "julia",
2224
m: "octave",
2325
r: "r",
24-
} as const;
26+
} as const satisfies { [ext: string]: IconName };
2527

2628
export function isNewFiletypeIconName(ext?: string) {
2729
return ext != null && ext in NEW_FILETYPE_ICONS;

src/packages/frontend/project/new/file-type-selector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export function FileTypeSelector({
468468
<NewFileButton
469469
name="Quarto"
470470
on_click={create_file}
471-
ext="rmd"
471+
ext="qmd"
472472
size={btnSize}
473473
active={btnActive("qmd")}
474474
/>
@@ -539,7 +539,7 @@ export function FileTypeSelector({
539539
const labelSlides = intl.formatMessage({
540540
id: "new.file-type-selector.slides.title",
541541
defaultMessage: "Slides",
542-
description: "Short label on a buton to create a new slideshow file",
542+
description: "Short label on a button to create a new slideshow file",
543543
});
544544

545545
return (
@@ -574,7 +574,7 @@ export function FileTypeSelector({
574574
id: "new.file-type-selector.whiteboard.title",
575575
defaultMessage: "Computational Whiteboard",
576576
description:
577-
"Short label on a buton to create a new whiteboard file",
577+
"Short label on a button to create a new whiteboard file",
578578
})}
579579
tip={intl.formatMessage({
580580
id: "new.file-type-selector.whiteboard.tooltip",

src/packages/frontend/project/new/new-file-page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Button, Input, Modal, Space } from "antd";
77
import { useEffect, useRef, useState } from "react";
88
import { defineMessage, FormattedMessage, useIntl } from "react-intl";
9+
910
import { default_filename } from "@cocalc/frontend/account";
1011
import { Alert, Col, Row } from "@cocalc/frontend/antd-bootstrap";
1112
import { filenameIcon } from "@cocalc/frontend/file-associations";

0 commit comments

Comments
 (0)