MCPcopy
hub / github.com/processing/p5.js / descriptionString

Function descriptionString

utils/shared-helpers.mjs:18–54  ·  view source on GitHub ↗
(node, parent)

Source from the content-addressed store, hash-verified

16}
17
18export function descriptionString(node, parent) {
19 if (!node) {
20 return '';
21 } else if (node.type === 'text') {
22 return node.value;
23 } else if (node.type === 'paragraph') {
24 const content = node.children.map(n => descriptionString(n, node)).join('');
25 if (parent && parent.children.length === 1) return content;
26 return '<p>' + content + '</p>\n';
27 } else if (node.type === 'code') {
28 let classes = [];
29 let attrs = '';
30 if (node.lang) {
31 classes.push(`language-${node.lang}`);
32 }
33 if (node.meta) {
34 classes.push(node.meta);
35 }
36 if (classes.length > 0) {
37 attrs=` class="${classes.join(' ')}"`;
38 }
39 return `<pre><code${attrs}>${node.value.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code></pre>`;
40 } else if (node.type === 'inlineCode') {
41 return '<code>' + node.value + '</code>';
42 } else if (node.type === 'list') {
43 const tag = node.type === 'ordered' ? 'ol' : 'ul';
44 return `<${tag}>` + node.children.map(n => descriptionString(n, node)).join('') + `</${tag}>`;
45 } else if (node.type === 'listItem') {
46 return '<li>' + node.children.map(n => descriptionString(n, node)).join('') + '</li>';
47 } else if (node.value) {
48 return node.value;
49 } else if (node.children) {
50 return node.children.map(n => descriptionString(n, node)).join('');
51 } else {
52 return '';
53 }
54}
55
56// TypeScript-specific version without HTML tags
57export function descriptionStringForTypeScript(node, parent) {

Callers 1

convert.mjsFile · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected