From 6f24bbbd606b6cfd1237e3bf740e73ffc23008be Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Mon, 29 Jan 2024 20:31:44 +0100 Subject: [PATCH] Support text field appendix --- assets/styles.css | 5 ++++ bin/generate-infobook-html.ts | 3 ++ .../InfoBookAppendixHandlerTextfield.ts | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 lib/infobook/appendix/InfoBookAppendixHandlerTextfield.ts diff --git a/assets/styles.css b/assets/styles.css index 149dcb2..83aa65e 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -167,6 +167,11 @@ hr { top: 1px; } +.appendix-textfield { + text-align: left; + padding: 10px; +} + .appendix .inputs { display: inline-block; vertical-align: middle; diff --git a/bin/generate-infobook-html.ts b/bin/generate-infobook-html.ts index ffe08da..7ef2ce3 100644 --- a/bin/generate-infobook-html.ts +++ b/bin/generate-infobook-html.ts @@ -9,6 +9,7 @@ import {InfoBookAppendixHandlerCraftingRecipe} from "../lib/infobook/appendix/In import {InfoBookAppendixHandlerSmeltingRecipe} from "../lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe"; import {InfoBookAppendixHandlerImage} from "../lib/infobook/appendix/InfoBookAppendixHandlerImage"; import {InfoBookAppendixHandlerKeybinding} from "../lib/infobook/appendix/InfoBookAppendixHandlerKeybinding"; +import {InfoBookAppendixHandlerTextfield} from "../lib/infobook/appendix/InfoBookAppendixHandlerTextfield"; import {IInfoBook} from "../lib/infobook/IInfoBook"; import {IInfobookPlugin} from "../lib/infobook/IInfobookPlugin"; import {InfoBookInitializer} from "../lib/infobook/InfoBookInitializer"; @@ -75,6 +76,8 @@ async function create() { new InfoBookAppendixHandlerImage(resourceLoader.getResourceHandler())); infoBookInitializer.registerAppendixHandler('keybinding', new InfoBookAppendixHandlerKeybinding(resourceLoader.getResourceHandler())); + infoBookInitializer.registerAppendixHandler('textfield', + new InfoBookAppendixHandlerTextfield(resourceLoader.getResourceHandler())); // Load plugins const assetsPaths = []; diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.ts b/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.ts new file mode 100644 index 0000000..868697d --- /dev/null +++ b/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.ts @@ -0,0 +1,30 @@ +import {ResourceHandler} from "../../resource/ResourceHandler"; +import {ISerializeContext} from "../../serialize/HtmlInfoBookSerializer"; +import {IFileWriter} from "../IFileWriter"; +import {IInfoAppendix} from "../IInfoAppendix"; +import {IInfoBookAppendixHandler} from "./IInfoBookAppendixHandler"; + +/** + * Handles text field appendices. + */ +export class InfoBookAppendixHandlerTextfield implements IInfoBookAppendixHandler { + + private readonly resourceHandler: ResourceHandler; + + constructor(resourceHandler: ResourceHandler) { + this.resourceHandler = resourceHandler; + } + + public createAppendix(data: any): IInfoAppendix { + const contents = data._ + .replace(/ /g, ' ') + .replace(/\n/g, '
'); + const scale = data.$.scale || 1; + return { + toHtml: (context: ISerializeContext, fileWriter: IFileWriter) => { + return `
${contents}
`; + }, + }; + } + +}