Skip to content

Commit 73a397f

Browse files
authored
Merge pull request #356 from mgreminger/md-left-justify
feat: document export improvements
2 parents b21c21f + c40fe98 commit 73a397f

22 files changed

+223
-61
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"plotly.js-basic-dist": "github:mgreminger/plotly.js#dist-basic-for-ep",
6060
"quick-lru": "^6.1.1",
6161
"quill": "^2.0.3",
62-
"quill-delta-to-markdown": "github:mgreminger/quill-delta-to-markdown#4c5f3a166ba85c90dc8378fccf4bf36b0a053e20",
62+
"quill-delta-to-markdown": "github:mgreminger/quill-delta-to-markdown#d35d6966b30873ff33ee1a2732b34d382bceead2",
6363
"workbox-window": "^6.5.4",
6464
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
6565
}

src/App.svelte

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
title: "Data Tables"
136136
},
137137
{
138-
path: "/EEosVXz7hywFwYimddQdu5",
138+
path: "/uEeEXzYZLWyfXxyTzaWpAN",
139139
title: "Python Extensions"
140140
},
141141
{
@@ -1938,7 +1938,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
19381938
}
19391939
}
19401940
1941-
async function getMarkdown(getShareableLink = false) {
1941+
async function getMarkdown(getShareableLink = false, centerEquations = false) {
19421942
let markdown = `# ${appState.title}\n`;
19431943
19441944
if (getShareableLink) {
@@ -1958,17 +1958,21 @@ Please include a link to this sheet in the email to assist in debugging the prob
19581958
modalInfo.modalOpen = false;
19591959
}
19601960
1961-
markdown += await cellList.getMarkdown();
1961+
markdown += await cellList.getMarkdown(centerEquations);
19621962
19631963
return markdown;
19641964
}
19651965
1966-
async function getDocument(docType: "docx" | "pdf" | "md" | "tex", getShareableLink = false) {
1967-
const markDown = "<!-- Created with EngineeringPaper.xyz -->\n" + await getMarkdown(getShareableLink);
1966+
async function getDocument(settings: {docType: "docx" | "pdf" | "md" | "tex",
1967+
getShareableLink: boolean,
1968+
centerEquations: boolean,
1969+
paperSize: "a4" | "letter"}) {
1970+
const markDown = "<!-- Created with EngineeringPaper.xyz -->\n" +
1971+
await getMarkdown(settings.getShareableLink, settings.centerEquations);
19681972
const upload_blob = new Blob([markDown], {type: "text/markdown"});
19691973
1970-
if (docType === "md") {
1971-
saveFileBlob(upload_blob, `${appState.title}.${docType}`);
1974+
if (settings.docType === "md") {
1975+
saveFileBlob(upload_blob, `${appState.title}.${settings.docType}`);
19721976
return
19731977
}
19741978
@@ -1979,15 +1983,21 @@ Please include a link to this sheet in the email to assist in debugging the prob
19791983
modalInfo = {state: "generatingDocument", modalOpen: true, heading: "Generating Document"};
19801984
19811985
try {
1982-
const response = await fetch(`${apiUrl}/docgen/${docType}`, {
1986+
let size_modifier: string;
1987+
if (settings.paperSize.toLowerCase() === "a4") {
1988+
size_modifier = "_a4";
1989+
} else {
1990+
size_modifier = "";
1991+
}
1992+
const response = await fetch(`${apiUrl}/docgen/${settings.docType}${size_modifier}`, {
19831993
method: "POST",
19841994
body: formData
19851995
});
19861996
19871997
if (response.ok) {
19881998
const fileBlob = await response.blob();
19891999
1990-
saveFileBlob(fileBlob, `${appState.title}.${docType}`);
2000+
saveFileBlob(fileBlob, `${appState.title}.${settings.docType}`);
19912001
19922002
modalInfo.modalOpen = false;
19932003
} else {
@@ -2001,7 +2011,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
20012011
throw new Error(`${response.status} ${errorMessage}`);
20022012
}
20032013
} catch (error) {
2004-
console.log(`Error creating ${docType} document: ${error}`);
2014+
console.log(`Error creating ${settings.docType} document: ${error}`);
20052015
modalInfo = {
20062016
state: "error",
20072017
error: error,
@@ -2917,7 +2927,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
29172927
<DownloadDocumentModal
29182928
bind:open={modalInfo.modalOpen}
29192929
downloadSheet={(e) => saveSheetToFile(e.detail.saveAs)}
2920-
downloadDocument={(e) => getDocument(e.detail.docType, e.detail.getShareableLink)}
2930+
downloadDocument={(e) => getDocument(e.detail)}
29212931
/>
29222932
{:else if modalInfo.state === "insertSheet"}
29232933
<InsertSheetModal

src/Cell.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
}
8282
});
8383
84-
export async function getMarkdown(): Promise<string> {
84+
export async function getMarkdown(centerEquations: boolean): Promise<string> {
8585
if (cellElement) {
86-
return await cellElement.getMarkdown?.() ?? "";
86+
return await cellElement.getMarkdown?.(centerEquations) ?? "";
8787
} else {
8888
return "";
8989
}

src/CellList.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
let scrollingContainer: HTMLElement;
3838
let sheetBody: HTMLUListElement;
3939
40-
export async function getMarkdown(): Promise<string> {
40+
export async function getMarkdown(centerEquations= false): Promise<string> {
4141
let markdown = "";
4242
4343
for (const cell of cellElements) {
4444
if (cell) {
45-
markdown += await cell.getMarkdown();
45+
markdown += await cell.getMarkdown(centerEquations);
4646
}
4747
}
4848

src/CodeCell.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
}
6060
});
6161
62-
export function getMarkdown() {
62+
export function getMarkdown(centerEquations: boolean) {
6363
return "```python\n" + codeCell.code + "\n```\n\n";
6464
}
6565

src/DataTableCell.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
let containerDiv: HTMLDivElement;
5959
let copyButtonText = $state("Copy Data");
6060
61-
export async function getMarkdown() {
61+
export async function getMarkdown(centerEquations: boolean) {
6262
const rows = (await dataTableCell
6363
.getSheetRows())
6464
.map(row => row.map(value => value.replaceAll('|', '\\|').replaceAll(':', '\\:')));

src/DeletedCell.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
let intervalId = null;
1919
let buttonElement: HTMLElement;
2020
21-
export function getMarkdown() {
21+
export function getMarkdown(centerEquations: boolean) {
2222
return "";
2323
}
2424

src/DocumentationCell.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
let hideToolbar = $derived(!(appState.activeCell === index));
2626
27-
export function getMarkdown(): string {
27+
export function getMarkdown(centerEquations: boolean): string {
2828
return deltaToMarkdown(documentationCell.documentationField.delta?.ops ?? "").replaceAll("\n", "\n\n").trimEnd() + "\n\n";
2929
}
3030

src/DownloadDocumentModal.svelte

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<script lang="ts">
2-
import { Modal, RadioButtonGroup, RadioButton, Checkbox } from "carbon-components-svelte";
2+
import { Modal, RadioButtonGroup, RadioButton, Checkbox, Select,
3+
SelectItem } from "carbon-components-svelte";
4+
import appState from "./stores.svelte";
35
46
interface Props {
57
open: boolean;
6-
downloadDocument: (arg: {detail: {docType: "docx" | "pdf" | "md" | "tex", getShareableLink: boolean}}) => void;
8+
downloadDocument: (arg: {detail: {docType: "docx" | "pdf" | "md" | "tex",
9+
getShareableLink: boolean,
10+
centerEquations: boolean,
11+
paperSize: "a4" | "letter"
12+
}}) => void;
713
downloadSheet: (arg: {detail: {saveAs: boolean}}) => void;
814
}
915
@@ -22,7 +28,11 @@
2228
if (docType === "epxyz") {
2329
downloadSheet({detail: {saveAs: saveAs}});
2430
} else {
25-
downloadDocument({detail: {docType: docType, getShareableLink: getShareableLink}});
31+
downloadDocument({detail: {docType: docType,
32+
getShareableLink: getShareableLink,
33+
centerEquations: appState.exportCenteredEquations,
34+
paperSize: appState.paperSize
35+
}});
2636
}
2737
}
2838
</script>
@@ -33,7 +43,6 @@
3343
flex-direction: column;
3444
gap: 20px;
3545
}
36-
3746
</style>
3847

3948
<Modal
@@ -74,12 +83,25 @@
7483
</div>
7584
{/if}
7685
<div>
77-
<div class="bx--label">Shareable Link</div>
86+
<Select
87+
labelText="Paper Size"
88+
bind:selected={appState.paperSize}
89+
disabled={docType === "epxyz" || docType === "md"}
90+
>
91+
<SelectItem value="letter" text="Letter" />
92+
<SelectItem value="a4" text="A4" />
93+
</Select>
94+
<div class="bx--label">Markdown Options</div>
7895
<Checkbox
7996
labelText="Create a shareable link and add it to the generated document (only applies to md, docx, pdf, and tex files, anyone with this private link will be able to view your original sheet)"
8097
bind:checked={getShareableLink}
8198
disabled={docType === "epxyz"}
8299
/>
100+
<Checkbox
101+
labelText="Center equations"
102+
bind:checked={appState.exportCenteredEquations}
103+
disabled={docType === "epxyz"}
104+
/>
83105
</div>
84106
</div>
85107
</Modal>

0 commit comments

Comments
 (0)