| 16 | } |
| 17 | |
| 18 | export 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, '<').replace(/>/g, '>')}</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 |
| 57 | export function descriptionStringForTypeScript(node, parent) { |