Compare commits

...

3 Commits

Author SHA1 Message Date
Abdullah Atta
ed914175cc web: wait 1s for math to render on pdf print 2023-11-18 14:18:11 +05:00
Abdullah Atta
72e8c0393b core: safe check for IS_DESKTOP_APP 2023-11-18 14:17:44 +05:00
Ammar Ahmed
ba39125c53 core: add padding to math block in exports 2023-11-18 13:27:01 +05:00
4 changed files with 24 additions and 6 deletions

View File

@@ -41,12 +41,21 @@ export async function exportToPDF(
iframe.style.width = "0";
iframe.style.height = "0";
iframe.style.border = "0";
iframe.loading = "eager";
iframe.onload = () => {
iframe.onload = async () => {
if (!iframe.contentWindow) return;
if (iframe.contentDocument) iframe.contentDocument.title = title;
iframe.contentWindow.onbeforeunload = () => closePrint(false);
iframe.contentWindow.onafterprint = () => closePrint(true);
if (
iframe.contentDocument &&
!!iframe.contentDocument.querySelector(".math-block,.math-inline")
) {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
iframe.contentWindow.print();
};

View File

@@ -32,7 +32,10 @@ const languagesList = await langen(
path.join(ROOT_DIR, "src", "utils", "templates", "html", "languages")
);
const languageIndex = `function hasRequire() {
return typeof require === "function" && !IS_DESKTOP_APP;
return (
typeof require === "function" &&
(typeof IS_DESKTOP_APP === "undefined" || !IS_DESKTOP_APP)
);
}
export async function loadLanguage(language) {

View File

@@ -41,7 +41,6 @@ async function preprocessHTML(templateData) {
const { content } = templateData;
let html = content.replaceAll(/<p([^>]*)><\/p>/gm, "<p$1><br/></p>");
console.log(html);
for (const attribute in replaceableAttributes) {
html = html.replaceAll(attribute, replaceableAttributes[attribute]);
}
@@ -60,7 +59,6 @@ async function preprocessHTML(templateData) {
: await import("katex/contrib/mhchem/mhchem.js");
for (const mathBlock of mathBlocks) {
const text = mathBlock.textContent;
console.log(text);
mathBlock.innerHTML = katex.renderToString(text, {
displayMode: true,
throwOnError: false
@@ -114,6 +112,9 @@ async function preprocessHTML(templateData) {
export default { buildHTML };
function hasRequire() {
// eslint-disable-next-line no-undef
return typeof require === "function" && !IS_DESKTOP_APP;
return (
typeof require === "function" &&
// eslint-disable-next-line no-undef
(typeof IS_DESKTOP_APP === "undefined" || !IS_DESKTOP_APP)
);
}

View File

@@ -46,6 +46,11 @@ const template = (data) => `<!DOCTYPE html>
color: #202124;
font-family: "Open Sans", "Noto Sans", Frutiger, Calibri, Myriad, Arial, Ubuntu, Helvetica, -apple-system, BlinkMacSystemFont, sans-serif;
}
.math-block {
padding-top: 20px;
padding-bottom: 20px;
}
h1,
h2,