diff --git a/apps/infoalloggi/Dockerfile b/apps/infoalloggi/Dockerfile index 349826b..ebb7089 100644 --- a/apps/infoalloggi/Dockerfile +++ b/apps/infoalloggi/Dockerfile @@ -81,7 +81,7 @@ ARG STORAGE_TOKEN ENV STORAGE_TOKEN=$STORAGE_TOKEN -RUN apk add --no-cache curl pandoc typst +RUN apk add --no-cache curl typst RUN addgroup -g 1001 -S nodejs RUN adduser -S nextjs -u 1001 diff --git a/apps/infoalloggi/package-lock.json b/apps/infoalloggi/package-lock.json index e575279..4846eed 100644 --- a/apps/infoalloggi/package-lock.json +++ b/apps/infoalloggi/package-lock.json @@ -86,6 +86,7 @@ "tailwind-scrollbar": "^4.0.2", "tailwindcss": "^4.2.2", "tunnel-rat": "^0.1.2", + "turndown": "^7.2.4", "tw-animate-css": "^1.4.0", "type-fest": "^5.5.0", "vaul": "^1.1.2", @@ -105,6 +106,7 @@ "@types/react": "^19.2.9", "@types/react-dom": "^19.2.3", "@types/react-is": "^19.2.0", + "@types/turndown": "^5.0.6", "@vitejs/plugin-react": "^6.0.1", "cross-env": "^10.1.0", "dotenv": "^17.3.1", @@ -1871,6 +1873,12 @@ "url": "https://opencollective.com/ramda" } }, + "node_modules/@mixmark-io/domino": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz", + "integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==", + "license": "BSD-2-Clause" + }, "node_modules/@napi-rs/canvas": { "version": "0.1.88", "license": "MIT", @@ -6885,6 +6893,13 @@ "@types/react": "*" } }, + "node_modules/@types/turndown": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@types/turndown/-/turndown-5.0.6.tgz", + "integrity": "sha512-ru00MoyeeouE5BX4gRL+6m/BsDfbRayOskWqUvh7CLGW+UXxHQItqALa38kKnOiZPqJrtzJUgAC2+F0rL1S4Pg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/use-sync-external-store": { "version": "0.0.6", "license": "MIT" @@ -13214,6 +13229,19 @@ "zustand": "^4.3.2" } }, + "node_modules/turndown": { + "version": "7.2.4", + "resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.4.tgz", + "integrity": "sha512-I8yFsfRzmzK0WV1pNNOA4A7y4RDfFxPRxb3t+e3ui14qSGOxGtiSP6GjeX+Y6CHb7HYaFj7ECUD7VE5kQMZWGQ==", + "license": "MIT", + "dependencies": { + "@mixmark-io/domino": "^2.2.0" + }, + "engines": { + "node": ">=18", + "npm": ">=9" + } + }, "node_modules/tw-animate-css": { "version": "1.4.0", "license": "MIT", diff --git a/apps/infoalloggi/package.json b/apps/infoalloggi/package.json index 843d38d..02c32a0 100644 --- a/apps/infoalloggi/package.json +++ b/apps/infoalloggi/package.json @@ -101,6 +101,7 @@ "tailwind-scrollbar": "^4.0.2", "tailwindcss": "^4.2.2", "tunnel-rat": "^0.1.2", + "turndown": "^7.2.4", "tw-animate-css": "^1.4.0", "type-fest": "^5.5.0", "vaul": "^1.1.2", @@ -120,6 +121,7 @@ "@types/react": "^19.2.9", "@types/react-dom": "^19.2.3", "@types/react-is": "^19.2.0", + "@types/turndown": "^5.0.6", "@vitejs/plugin-react": "^6.0.1", "cross-env": "^10.1.0", "dotenv": "^17.3.1", diff --git a/apps/infoalloggi/src/server/controllers/event_queue.controller.ts b/apps/infoalloggi/src/server/controllers/event_queue.controller.ts index b184cf9..35e454d 100644 --- a/apps/infoalloggi/src/server/controllers/event_queue.controller.ts +++ b/apps/infoalloggi/src/server/controllers/event_queue.controller.ts @@ -21,7 +21,7 @@ import { import { db } from "~/server/db"; import { NewMail, type NewMailProps } from "~/server/services/mailer"; import { - convertHtmlToTypst, + convertHTMLToMD, TypstGenerate, } from "~/server/services/typst.service"; @@ -64,7 +64,7 @@ const generatePdfContent = async (params: GeneratedAttachmentTypes) => { }); } - const stringa = convertHtmlToTypst(data.stringa_value); + const stringa = convertHTMLToMD(data.stringa_value); const pdf = await TypstGenerate({ templateId: "testi.typ", data: { stringa }, diff --git a/apps/infoalloggi/src/server/services/typst.service.ts b/apps/infoalloggi/src/server/services/typst.service.ts index 765b093..a870d9b 100644 --- a/apps/infoalloggi/src/server/services/typst.service.ts +++ b/apps/infoalloggi/src/server/services/typst.service.ts @@ -1,12 +1,13 @@ -import { exec, execSync } from "node:child_process"; +import { exec } from "node:child_process"; import fs from "node:fs/promises"; import path from "node:path"; import { promisify } from "node:util"; import { TRPCError } from "@trpc/server"; +import TurndownService from "turndown"; import type { EstrattoContoData } from "~/server/api/routers/stripe_reports"; const execPromise = promisify(exec); -const projectRoot = process.cwd() +const projectRoot = process.cwd(); const fontsPath = path.join(projectRoot, "typst", "fonts"); const tmpDir = path.join(projectRoot, "tmp"); @@ -15,6 +16,7 @@ const tmpDir = path.join(projectRoot, "tmp"); * Converts HTML to Typst markup using Pandoc. * works on Windows & Linux. */ +/* DISABLED BECAUSE PANDOC IS HEAVY export function convertHtmlToTypst(html: string): string { try { // We pass the HTML via 'input' which writes to the process stdin @@ -33,6 +35,10 @@ export function convertHtmlToTypst(html: string): string { cause: error instanceof Error ? error : undefined, }); } +}*/ +const turndownService = new TurndownService(); +export function convertHTMLToMD(html: string): string { + return turndownService.turndown(html); } type EstrattoContoTemplate = { diff --git a/apps/infoalloggi/typst/testi.typ b/apps/infoalloggi/typst/testi.typ index 43099ff..228dabf 100644 --- a/apps/infoalloggi/typst/testi.typ +++ b/apps/infoalloggi/typst/testi.typ @@ -1,4 +1,4 @@ - +#import "@preview/cmarker:0.1.8" #let data = sys.inputs.at("data", default: none) @@ -17,7 +17,6 @@ ) } -#eval(data.stringa, mode: "markup") - - +//#eval(data.stringa, mode: "markup") +#cmarker.render(data.stringa)