heymenn commited on
Commit
57e048e
·
1 Parent(s): 36fa73c

Fix methodology output

Browse files
Files changed (1) hide show
  1. components/InnovationCard.tsx +74 -2
components/InnovationCard.tsx CHANGED
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
2
  import { Innovation, Classification, ResultResponse } from '../types';
3
  import { ChevronDown, ChevronUp, Trash2, Check, Zap, FileText } from 'lucide-react';
4
  import { COLOR_MAP } from '../constants';
 
5
 
6
  interface InnovationCardProps {
7
  innovation: ResultResponse;
@@ -22,6 +23,7 @@ const InnovationCard: React.FC<InnovationCardProps> = ({ innovation, onClassify
22
  console.log(innovation)
23
  const contextText = innovation.context;
24
  const problemText = innovation.problem;
 
25
 
26
  return (
27
  <div
@@ -83,13 +85,83 @@ const InnovationCard: React.FC<InnovationCardProps> = ({ innovation, onClassify
83
  </div>
84
 
85
  {isExpanded && (
86
- <div
 
 
 
87
  className="flex flex-col gap-2 m-2"
88
- dangerouslySetInnerHTML={{ __html: innovation.content }}
89
  />
 
90
  )}
91
  </div>
92
  );
93
  };
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  export default InnovationCard;
 
2
  import { Innovation, Classification, ResultResponse } from '../types';
3
  import { ChevronDown, ChevronUp, Trash2, Check, Zap, FileText } from 'lucide-react';
4
  import { COLOR_MAP } from '../constants';
5
+ import { format } from 'path';
6
 
7
  interface InnovationCardProps {
8
  innovation: ResultResponse;
 
23
  console.log(innovation)
24
  const contextText = innovation.context;
25
  const problemText = innovation.problem;
26
+ const methodologyText = formatToHTML(innovation.methodology)
27
 
28
  return (
29
  <div
 
85
  </div>
86
 
87
  {isExpanded && (
88
+
89
+ <div className='px-4 pb-4 bg-slate-50 border-t border-slate-100 pt-3 text-sm'>
90
+ <p className="font-semibold text-slate-700 mb-1">Methodology</p>
91
+ <div
92
  className="flex flex-col gap-2 m-2"
93
+ dangerouslySetInnerHTML={{ __html: methodologyText }}
94
  />
95
+ </div>
96
  )}
97
  </div>
98
  );
99
  };
100
 
101
+ function formatToHTML(rawInput) {
102
+ if (!rawInput) return "";
103
+
104
+ // Convert bold markdown (**text**) to <strong>text</strong>
105
+ let formatted = rawInput.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>");
106
+
107
+ // Split into lines (handle cases where everything is in one line)
108
+ formatted = formatted.replace(/(\d+\.)/g, "\n$1");
109
+ formatted = formatted.replace(/\*/g, "\n*");
110
+
111
+ const lines = formatted.split("\n").map(line => line.trim()).filter(Boolean);
112
+
113
+ let html = "";
114
+ let inOrderedList = false;
115
+ let inUnorderedList = false;
116
+
117
+ lines.forEach(line => {
118
+
119
+ // Ordered list (e.g., "1. Something")
120
+ if (/^\d+\.\s/.test(line)) {
121
+ if (!inOrderedList) {
122
+ html += "<ol>";
123
+ inOrderedList = true;
124
+ }
125
+ if (inUnorderedList) {
126
+ html += "</ul>";
127
+ inUnorderedList = false;
128
+ }
129
+ html += `<li>${line.replace(/^\d+\.\s/, "")}</li>`;
130
+ }
131
+
132
+ // Unordered list (e.g., "* Something")
133
+ else if (/^\*\s/.test(line)) {
134
+ if (!inUnorderedList) {
135
+ html += "<ul>";
136
+ inUnorderedList = true;
137
+ }
138
+ if (inOrderedList) {
139
+ html += "</ol>";
140
+ inOrderedList = false;
141
+ }
142
+ html += `<li>${line.replace(/^\*\s/, "")}</li>`;
143
+ }
144
+
145
+ // Paragraph fallback
146
+ else {
147
+ if (inOrderedList) {
148
+ html += "</ol>";
149
+ inOrderedList = false;
150
+ }
151
+ if (inUnorderedList) {
152
+ html += "</ul>";
153
+ inUnorderedList = false;
154
+ }
155
+ html += `<p>${line}</p>`;
156
+ }
157
+ });
158
+
159
+ // Close any open lists
160
+ if (inOrderedList) html += "</ol>";
161
+ if (inUnorderedList) html += "</ul>";
162
+
163
+ return html;
164
+ }
165
+
166
+
167
  export default InnovationCard;