Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-harness/blob/main/cli/src/ui/Markdown.tsx # omega-harness Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-harness / cli / src / ui / Markdown.tsx` 127 lines · 3077 bytes Raw Blame History 1 import React from 'react'; 2 import { Box, Text } from 'ink'; 3 import { THEME } from '../brand.js'; 4 5 interface MarkdownProps { 6 text: string; 7 } 8 9 function renderInline(line: string): React.ReactNode[] { 10 const nodes: React.ReactNode[] = []; 11 // Split on inline code `...` and bold **...** 12 const pattern = /(`[^`]+`|\*\*[^*]+\*\*)/g; 13 let lastIndex = 0; 14 let key = 0; 15 16 for (const match of line.matchAll(pattern)) { 17 const idx = match.index ?? 0; 18 if (idx > lastIndex) { 19 nodes.push({line.slice(lastIndex, idx)}); 20 } 21 const token = match[0]; 22 if (token.startsWith('`') && token.endsWith('`')) { 23 nodes.push( 24 25 {token.slice(1, -1)} 26 27 ); 28 } else if (token.startsWith('**') && token.endsWith('**')) { 29 nodes.push( 30 31 {token.slice(2, -2)} 32 33 ); 34 } 35 lastIndex = idx + token.length; 36 } 37 38 if (lastIndex < line.length) { 39 nodes.push({line.slice(lastIndex)}); 40 } 41 return nodes.length > 0 ? nodes : [{line}]; 42 } 43 44 export const Markdown: React.FC = ({ text }) => { 45 const lines = text.split(/\r?\n/); 46 const blocks: React.ReactNode[] = []; 47 let inCode = false; 48 let codeLang = ''; 49 let codeLines: string[] = []; 50 let blockKey = 0; 51 52 const flushCode = () => { 53 blocks.push( 54 62 {codeLang ? ( 63 64 {codeLang} 65 66 ) : null} 67 {codeLines.join('\n')} 68 69 ); 70 codeLines = []; 71 codeLang = ''; 72 }; 73 74 for (let i = 0; i < lines.length; i++) { 75 const line = lines[i]; 76 if (line.trimStart().startsWith('```')) { 77 if (!inCode) { 78 inCode = true; 79 codeLang = line.trimStart().slice(3).trim(); 80 } else { 81 inCode = false; 82 flushCode(); 83 } 84 continue; 85 } 86 87 if (inCode) { 88 codeLines.push(line); 89 continue; 90 } 91 92 const heading = line.match(/^(#{1,3})\s+(.*)$/); 93 if (heading) { 94 blocks.push( 95 96 {heading[2]} 97 98 ); 99 continue; 100 } 101 102 const bullet = line.match(/^(\s*)[-*]\s+(.*)$/); 103 if (bullet) { 104 blocks.push( 105 106 {bullet[1]} 107 • 108 {renderInline(bullet[2])} 109 110 ); 111 continue; 112 } 113 114 if (line.trim() === '') { 115 blocks.push( ); 116 continue; 117 } 118 119 blocks.push({renderInline(line)}); 120 } 121 122 if (inCode && codeLines.length > 0) { 123 flushCode(); 124 } 125 126 return {blocks}; 127 };