From 8490c0efac68d043c04761fd5f3507d39ceefef3 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Sun, 15 Oct 2023 00:13:29 -0400 Subject: [PATCH] Generic HTML encode util --- src/projector/html.ts | 40 ++++++++++++++-------------------------- src/util.ts | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/projector/html.ts b/src/projector/html.ts index f6e65d2..2650336 100644 --- a/src/projector/html.ts +++ b/src/projector/html.ts @@ -1,26 +1,7 @@ import {writeFile} from 'fs/promises'; import {Projector} from '../projector'; - -/** - * HTML encode. - * - * @param s Raw strings. - * @returns HTML strings. - */ -function he(s: string) { - return s.replace(/&/g, '&').replace(//g, '>'); -} - -/** - * HTML encode an attribute. - * - * @param s Raw strings. - * @returns HTML strings. - */ -function ha(s: string) { - return he(s).replace(/"/g, '"'); -} +import {htmlEncode} from '../util'; /** * ProjectorHtml object. @@ -301,7 +282,9 @@ export class ProjectorHtml extends Projector { '', ' ', ' ', - ...(title === null ? [] : [` ${he(title)}`]), + ...(title === null + ? [] + : [` ${htmlEncode(title)}`]), ' ', '