sub pandoc for turndown
This commit is contained in:
parent
573cd0b8b9
commit
edd0c0512e
6 changed files with 44 additions and 9 deletions
|
|
@ -81,7 +81,7 @@ ARG STORAGE_TOKEN
|
||||||
ENV STORAGE_TOKEN=$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 addgroup -g 1001 -S nodejs
|
||||||
RUN adduser -S nextjs -u 1001
|
RUN adduser -S nextjs -u 1001
|
||||||
|
|
|
||||||
28
apps/infoalloggi/package-lock.json
generated
28
apps/infoalloggi/package-lock.json
generated
|
|
@ -86,6 +86,7 @@
|
||||||
"tailwind-scrollbar": "^4.0.2",
|
"tailwind-scrollbar": "^4.0.2",
|
||||||
"tailwindcss": "^4.2.2",
|
"tailwindcss": "^4.2.2",
|
||||||
"tunnel-rat": "^0.1.2",
|
"tunnel-rat": "^0.1.2",
|
||||||
|
"turndown": "^7.2.4",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"type-fest": "^5.5.0",
|
"type-fest": "^5.5.0",
|
||||||
"vaul": "^1.1.2",
|
"vaul": "^1.1.2",
|
||||||
|
|
@ -105,6 +106,7 @@
|
||||||
"@types/react": "^19.2.9",
|
"@types/react": "^19.2.9",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@types/react-is": "^19.2.0",
|
"@types/react-is": "^19.2.0",
|
||||||
|
"@types/turndown": "^5.0.6",
|
||||||
"@vitejs/plugin-react": "^6.0.1",
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
"cross-env": "^10.1.0",
|
"cross-env": "^10.1.0",
|
||||||
"dotenv": "^17.3.1",
|
"dotenv": "^17.3.1",
|
||||||
|
|
@ -1871,6 +1873,12 @@
|
||||||
"url": "https://opencollective.com/ramda"
|
"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": {
|
"node_modules/@napi-rs/canvas": {
|
||||||
"version": "0.1.88",
|
"version": "0.1.88",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
@ -6885,6 +6893,13 @@
|
||||||
"@types/react": "*"
|
"@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": {
|
"node_modules/@types/use-sync-external-store": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
|
|
@ -13214,6 +13229,19 @@
|
||||||
"zustand": "^4.3.2"
|
"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": {
|
"node_modules/tw-animate-css": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@
|
||||||
"tailwind-scrollbar": "^4.0.2",
|
"tailwind-scrollbar": "^4.0.2",
|
||||||
"tailwindcss": "^4.2.2",
|
"tailwindcss": "^4.2.2",
|
||||||
"tunnel-rat": "^0.1.2",
|
"tunnel-rat": "^0.1.2",
|
||||||
|
"turndown": "^7.2.4",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"type-fest": "^5.5.0",
|
"type-fest": "^5.5.0",
|
||||||
"vaul": "^1.1.2",
|
"vaul": "^1.1.2",
|
||||||
|
|
@ -120,6 +121,7 @@
|
||||||
"@types/react": "^19.2.9",
|
"@types/react": "^19.2.9",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@types/react-is": "^19.2.0",
|
"@types/react-is": "^19.2.0",
|
||||||
|
"@types/turndown": "^5.0.6",
|
||||||
"@vitejs/plugin-react": "^6.0.1",
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
"cross-env": "^10.1.0",
|
"cross-env": "^10.1.0",
|
||||||
"dotenv": "^17.3.1",
|
"dotenv": "^17.3.1",
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import {
|
||||||
import { db } from "~/server/db";
|
import { db } from "~/server/db";
|
||||||
import { NewMail, type NewMailProps } from "~/server/services/mailer";
|
import { NewMail, type NewMailProps } from "~/server/services/mailer";
|
||||||
import {
|
import {
|
||||||
convertHtmlToTypst,
|
convertHTMLToMD,
|
||||||
TypstGenerate,
|
TypstGenerate,
|
||||||
} from "~/server/services/typst.service";
|
} 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({
|
const pdf = await TypstGenerate({
|
||||||
templateId: "testi.typ",
|
templateId: "testi.typ",
|
||||||
data: { stringa },
|
data: { stringa },
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
import { exec, execSync } from "node:child_process";
|
import { exec } from "node:child_process";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
import TurndownService from "turndown";
|
||||||
import type { EstrattoContoData } from "~/server/api/routers/stripe_reports";
|
import type { EstrattoContoData } from "~/server/api/routers/stripe_reports";
|
||||||
|
|
||||||
const execPromise = promisify(exec);
|
const execPromise = promisify(exec);
|
||||||
const projectRoot = process.cwd()
|
const projectRoot = process.cwd();
|
||||||
const fontsPath = path.join(projectRoot, "typst", "fonts");
|
const fontsPath = path.join(projectRoot, "typst", "fonts");
|
||||||
|
|
||||||
const tmpDir = path.join(projectRoot, "tmp");
|
const tmpDir = path.join(projectRoot, "tmp");
|
||||||
|
|
@ -15,6 +16,7 @@ const tmpDir = path.join(projectRoot, "tmp");
|
||||||
* Converts HTML to Typst markup using Pandoc.
|
* Converts HTML to Typst markup using Pandoc.
|
||||||
* works on Windows & Linux.
|
* works on Windows & Linux.
|
||||||
*/
|
*/
|
||||||
|
/* DISABLED BECAUSE PANDOC IS HEAVY
|
||||||
export function convertHtmlToTypst(html: string): string {
|
export function convertHtmlToTypst(html: string): string {
|
||||||
try {
|
try {
|
||||||
// We pass the HTML via 'input' which writes to the process stdin
|
// 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,
|
cause: error instanceof Error ? error : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
const turndownService = new TurndownService();
|
||||||
|
export function convertHTMLToMD(html: string): string {
|
||||||
|
return turndownService.turndown(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
type EstrattoContoTemplate = {
|
type EstrattoContoTemplate = {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
#import "@preview/cmarker:0.1.8"
|
||||||
|
|
||||||
|
|
||||||
#let data = sys.inputs.at("data", default: none)
|
#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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue