From c08017bd5914830cc0c682d1ced50790e1dcdb6c Mon Sep 17 00:00:00 2001 From: Nick Playfair <842413+nplayfair@users.noreply.github.com> Date: Thu, 12 Jun 2025 16:44:44 +0100 Subject: [PATCH] Prettify HTML code output --- package-lock.json | 14 +++++++++++++- package.json | 3 ++- src/index.ts | 9 +-------- src/utils.ts | 11 ++++++++++- tsconfig.json | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index a89f374..812fbda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "2.0.0", "license": "MIT", "dependencies": { - "csvtojson": "^2.0.10" + "csvtojson": "^2.0.10", + "htmlfy": "^0.7.5" }, "devDependencies": { "@types/csvtojson": "^1.1.5", @@ -2203,6 +2204,12 @@ "safe-buffer": "~5.1.0" } }, + "node_modules/htmlfy": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/htmlfy/-/htmlfy-0.7.5.tgz", + "integrity": "sha512-woog97QSD0MJVXDs4nNz3S/XIb+wa/UgunpaI29tbXaTB9SlNvQalw1XolE4m3BPp3xkJMx96I27Lb/clesPLA==", + "license": "MIT" + }, "node_modules/http-deceiver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", @@ -6036,6 +6043,11 @@ } } }, + "htmlfy": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/htmlfy/-/htmlfy-0.7.5.tgz", + "integrity": "sha512-woog97QSD0MJVXDs4nNz3S/XIb+wa/UgunpaI29tbXaTB9SlNvQalw1XolE4m3BPp3xkJMx96I27Lb/clesPLA==" + }, "http-deceiver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", diff --git a/package.json b/package.json index e6f4a53..7c33340 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "author": "nplayfair", "license": "MIT", "dependencies": { - "csvtojson": "^2.0.10" + "csvtojson": "^2.0.10", + "htmlfy": "^0.7.5" }, "devDependencies": { "@types/csvtojson": "^1.1.5", diff --git a/src/index.ts b/src/index.ts index ef2e6fd..1da67e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { getBOM } from './csvToJSON'; import { PartsTable } from './table'; import { headers } from './config'; +import { printHTMLtable } from './utils'; //DOM elements const input = document.getElementById('csvInput') as HTMLInputElement; @@ -53,14 +54,6 @@ async function createTable() { printHTMLtable(tableMarkup as HTMLTableElement, partsHTML); } -//Print HTML code -async function printHTMLtable( - table: HTMLTableElement, - codeBlock: HTMLPreElement, -) { - codeBlock.innerText = table.outerHTML; -} - //Add event listener input.addEventListener('change', handleUpload); diff --git a/src/utils.ts b/src/utils.ts index 4700a3d..e7b17e5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,13 @@ -import { rejectedParts } from './config'; +import { prettify } from 'htmlfy'; + +//Print HTML code +export async function printHTMLtable( + table: HTMLTableElement, + codeBlock: HTMLPreElement, +) { + codeBlock.innerText = prettify(table.outerHTML); +} + // no longer needed // export function isJunk(element: Part): boolean { // // Returns true if element is in the rejected list diff --git a/tsconfig.json b/tsconfig.json index 958643b..c71c481 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -46,7 +46,7 @@ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */