(block: TextBlock)
| 95 | } |
| 96 | |
| 97 | export function createMarkdownForTextBlock(block: TextBlock): string { |
| 98 | const content = block.content ?? '' |
| 99 | |
| 100 | if (block.type === 'text-cell-h1') { |
| 101 | return `# ${escapeMarkdown(content)}` |
| 102 | } |
| 103 | |
| 104 | if (block.type === 'text-cell-h2') { |
| 105 | return `## ${escapeMarkdown(content)}` |
| 106 | } |
| 107 | |
| 108 | if (block.type === 'text-cell-h3') { |
| 109 | return `### ${escapeMarkdown(content)}` |
| 110 | } |
| 111 | |
| 112 | if (block.type === 'text-cell-bullet') { |
| 113 | const metadata = block.metadata as BulletTextBlockMetadata |
| 114 | const indent = ' '.repeat(metadata?.indent_level ?? 0) |
| 115 | return `${indent}- ${escapeMarkdown(content)}` |
| 116 | } |
| 117 | |
| 118 | if (block.type === 'text-cell-todo') { |
| 119 | const metadata = block.metadata as TodoTextBlockMetadata |
| 120 | const checkbox = metadata?.checked ? '[x]' : '[ ]' |
| 121 | |
| 122 | return `- ${checkbox} ${escapeMarkdown(content)}` |
| 123 | } |
| 124 | |
| 125 | if (block.type === 'text-cell-callout') { |
| 126 | return `> ${escapeMarkdown(content)}` |
| 127 | } |
| 128 | |
| 129 | if (block.type === 'text-cell-p') { |
| 130 | return escapeMarkdown(content) |
| 131 | } |
| 132 | |
| 133 | throw new UnsupportedBlockTypeError('Unhandled block type.') |
| 134 | } |
| 135 | |
| 136 | export function stripMarkdownFromTextBlock(block: TextBlock): string { |
| 137 | const content = block.content ?? '' |
no test coverage detected