Skip to content

Commit 06c3ec0

Browse files
committed
feat: improve code handling a bit, still quick and dirty
1 parent fb1d04b commit 06c3ec0

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/components/openEHRQuest.tsx

+34-10
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,37 @@ const OpenEHRQuest: React.FC = () => {
178178

179179
const currentLevel = levels[gameState.currentLevel];
180180

181+
const renderChallenge = (challenge: string, language: string) => {
182+
const parts = challenge.split(/(\n\n)/);
183+
let inCodeBlock = false;
184+
185+
return parts.map((part, index) => {
186+
if (part === '\n\n') {
187+
return <br key={`br-${index}`} />;
188+
}
189+
190+
if (part.trim().startsWith('<') || part.trim().startsWith('{')) {
191+
inCodeBlock = true;
192+
}
193+
194+
if (inCodeBlock) {
195+
return (
196+
<CodeHighlight
197+
key={`code-${index}`}
198+
code={part.trim()}
199+
language={language}
200+
/>
201+
);
202+
}
203+
204+
return (
205+
<p key={`text-${index}`} className="mb-2">
206+
{part}
207+
</p>
208+
);
209+
});
210+
};
211+
181212
return (
182213
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100 p-4">
183214
<Card className="w-full max-w-4xl">
@@ -206,16 +237,9 @@ const OpenEHRQuest: React.FC = () => {
206237
</Alert>
207238
<div className="my-4">
208239
<h2 className="text-xl font-semibold mb-2">Challenge:</h2>
209-
{currentLevel.language !== 'text' ? (
210-
<CodeHighlight
211-
code={currentLevel.challenge}
212-
language={currentLevel.language}
213-
/>
214-
) : (
215-
<pre className="bg-gray-800 text-white p-4 rounded-md overflow-x-auto whitespace-pre-wrap break-words">
216-
<code>{currentLevel.challenge}</code>
217-
</pre>
218-
)}{' '}
240+
<div className="bg-gray-800 text-white p-4 rounded-md overflow-x-auto whitespace-pre-wrap break-words">
241+
{renderChallenge(currentLevel.challenge, currentLevel.language)}
242+
</div>{' '}
219243
</div>
220244
<div className="space-y-2">
221245
{currentLevel.options.map((option, index) => (

0 commit comments

Comments
 (0)