MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / render

Method render

src/lib/FancyError.ts:198–255  ·  view source on GitHub ↗
(props: FancyErrorProps = {})

Source from the content-addressed store, hash-verified

196 }
197
198 static render (props: FancyErrorProps = {}): string {
199 let html = '<div class="error-section">';
200 for (const key of Object.keys(props)) {
201 const value = props[key];
202 if (typeof value === 'string' || typeof value === 'number') {
203 html += `<p><b>${key}</b>: ${value}</p>`;
204 } else if (value instanceof Array) {
205 html += `<details open><summary><b>${key}</b>:</summary><ul>`;
206 for (const item of value) {
207 html += `<li>${item}</li>`;
208 }
209 html += '</ul></details>';
210 } else if (value instanceof NodeList) {
211 html += `<p><b>${key}</b>:<br><pre>`;
212 for (const item of value) {
213 if (item instanceof Element) {
214 html += `<code class='language-markup'>${item.outerHTML.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')}</code>`;
215 }
216 }
217 html += '</pre></p>';
218 }
219 }
220 html += '</div>';
221
222 for (const key of Object.keys(props)) {
223 const value = props[key];
224 if (typeof value === 'object' && !(value instanceof Array) && !(value instanceof NodeList)) {
225 const obj = value as FancyErrorProps;
226 html += `<hr class='separator--material'/><h3>${Text.capitalize(key)}</h3><div class='error-section'>`;
227 for (const property of Object.keys(obj)) {
228 if (property.indexOf('_') === 0) {
229 html += `<p>${obj[property]}</p>`;
230 } else {
231 const propValue = obj[property];
232 if (typeof propValue === 'string' || typeof propValue === 'number') {
233 html += `<p><b>${property}</b>: ${propValue}</p>`;
234 } else if (propValue instanceof Array) {
235 html += `<details open><summary><b>${property}</b>:</summary><ul>`;
236 for (const item of propValue) {
237 html += `<li>${item}</li>`;
238 }
239 html += '</ul></details>';
240 } else if (propValue instanceof NodeList) {
241 html += `<p><b>${property}</b>:<br><pre>`;
242 for (const item of propValue) {
243 if (item instanceof Element) {
244 html += `<code class='language-markup'>${item.outerHTML.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')}</code>`;
245 }
246 }
247 html += '</pre></p>';
248 }
249 }
250 }
251 html += '</div>';
252 }
253 }
254 return html;
255 }

Callers 1

generateModalHtmlMethod · 0.45

Calls 2

replaceMethod · 0.80
keysMethod · 0.65

Tested by

no test coverage detected