From ea15c99d9ffa7ca59e9a44cdcccc492cca5a4ac0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 12 Jun 2023 18:15:05 -0300 Subject: html: inspect.custom() annotations for html classes --- src/util/html.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/util/html.js b/src/util/html.js index b75820e8..f2456565 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -1,5 +1,7 @@ // Some really simple functions for formatting HTML content. +import {inspect} from 'util'; + import * as commonValidators from '../data/things/validators.js'; import {empty} from './sugar.js'; @@ -396,6 +398,22 @@ export class Tag { .filter(Boolean) .join(joiner); } + + [inspect.custom]() { + if (this.tagName) { + if (empty(this.content)) { + return `Tag <${this.tagName} />`; + } else { + return `Tag <${this.tagName}> (${this.content.length} items)`; + } + } else { + if (empty(this.content)) { + return `Tag (no name)`; + } else { + return `Tag (no name, ${this.content.length} items)`; + } + } + } } export class Attributes { @@ -781,6 +799,15 @@ export class Template { toString() { return this.content.toString(); } + + [inspect.custom]() { + const {annotation} = this.description; + if (annotation) { + return `Template "${annotation}"`; + } else { + return `Template (no annotation)`; + } + } } export function stationery(description) { @@ -801,4 +828,13 @@ export class Stationery { template() { return new Template(this.#templateDescription); } + + [inspect.custom]() { + const {annotation} = this.#templateDescription; + if (annotation) { + return `Stationery "${annotation}"`; + } else { + return `Stationery (no annotation)`; + } + } } -- cgit 1.3.0-6-gf8a5