Prettify HTML code output

This commit is contained in:
Nick Playfair 2025-06-12 16:44:44 +01:00
parent a3f3c2ed09
commit c08017bd59
5 changed files with 27 additions and 12 deletions

14
package-lock.json generated
View File

@ -9,7 +9,8 @@
"version": "2.0.0", "version": "2.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"csvtojson": "^2.0.10" "csvtojson": "^2.0.10",
"htmlfy": "^0.7.5"
}, },
"devDependencies": { "devDependencies": {
"@types/csvtojson": "^1.1.5", "@types/csvtojson": "^1.1.5",
@ -2203,6 +2204,12 @@
"safe-buffer": "~5.1.0" "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": { "node_modules/http-deceiver": {
"version": "1.2.7", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", "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": { "http-deceiver": {
"version": "1.2.7", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", "resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz",

View File

@ -10,7 +10,8 @@
"author": "nplayfair", "author": "nplayfair",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"csvtojson": "^2.0.10" "csvtojson": "^2.0.10",
"htmlfy": "^0.7.5"
}, },
"devDependencies": { "devDependencies": {
"@types/csvtojson": "^1.1.5", "@types/csvtojson": "^1.1.5",

View File

@ -2,6 +2,7 @@
import { getBOM } from './csvToJSON'; import { getBOM } from './csvToJSON';
import { PartsTable } from './table'; import { PartsTable } from './table';
import { headers } from './config'; import { headers } from './config';
import { printHTMLtable } from './utils';
//DOM elements //DOM elements
const input = document.getElementById('csvInput') as HTMLInputElement; const input = document.getElementById('csvInput') as HTMLInputElement;
@ -53,14 +54,6 @@ async function createTable() {
printHTMLtable(tableMarkup as HTMLTableElement, partsHTML); printHTMLtable(tableMarkup as HTMLTableElement, partsHTML);
} }
//Print HTML code
async function printHTMLtable(
table: HTMLTableElement,
codeBlock: HTMLPreElement,
) {
codeBlock.innerText = table.outerHTML;
}
//Add event listener //Add event listener
input.addEventListener('change', handleUpload); input.addEventListener('change', handleUpload);

View File

@ -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 // no longer needed
// export function isJunk(element: Part): boolean { // export function isJunk(element: Part): boolean {
// // Returns true if element is in the rejected list // // Returns true if element is in the rejected list

View File

@ -46,7 +46,7 @@
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
/* Module Resolution Options */ /* 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. */ // "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'. */ // "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. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */