Markishime commited on
Commit
5ed085c
·
1 Parent(s): 9de4c72

Fix: Improve table formatting in Step 3 and Step 6

Browse files

- Convert <br> tags to proper line breaks in formatted_analysis
- Extract and render markdown tables properly in Step 3 formatted analysis
- Extract and render markdown tables properly in Step 6 content
- Improve paragraph splitting and display formatting for better readability

Files changed (1) hide show
  1. modules/results.py +42 -7
modules/results.py CHANGED
@@ -15696,10 +15696,27 @@ def display_step3_solution_recommendations(analysis_data):
15696
  formatted_content = formatted_block.group(1).strip()
15697
  # Clean up persona language
15698
  clean_content = sanitize_persona_and_enforce_article(formatted_content)
 
 
 
 
15699
  # Normalize markdown formatting
15700
  normalized_content = normalize_markdown_block_for_step3(clean_content)
15701
  st.markdown(f"### 📋 {t('detailed_analysis', 'Detailed Analysis')}")
15702
- st.markdown(normalized_content)
 
 
 
 
 
 
 
 
 
 
 
 
 
15703
  st.markdown("")
15704
  return # Exit early to avoid showing duplicate content
15705
  except Exception:
@@ -16122,13 +16139,25 @@ def display_regenerative_agriculture_content(analysis_data):
16122
 
16123
  # Only display if content remains after filtering
16124
  if detailed_text.strip():
 
 
 
 
16125
  st.markdown(f"#### 📋 {t('detailed_analysis', 'Detailed Analysis')}")
16126
- st.markdown(
16127
- f'<div style="margin-bottom: 20px; padding: 20px; background: linear-gradient(135deg, #ffffff, #f8f9fa); border: 1px solid #e9ecef; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.08);">'
16128
- f'<div style="color: #2c3e50; line-height: 1.7;">{detailed_text}</div>'
16129
- f'</div>',
16130
- unsafe_allow_html=True
16131
- )
 
 
 
 
 
 
 
 
16132
 
16133
  # Nuclear option: remove any Economic Analysis with braces
16134
  if re.search(r"Economic Analysis:\s*\{", detailed_text, re.IGNORECASE):
@@ -16169,6 +16198,12 @@ def display_regenerative_agriculture_content(analysis_data):
16169
  )
16170
 
16171
  detailed_text = sanitize_persona_and_enforce_article(detailed_text)
 
 
 
 
 
 
16172
 
16173
  # Process HTML/XML tables in the content first
16174
  processed_text = process_html_tables(detailed_text)
 
15696
  formatted_content = formatted_block.group(1).strip()
15697
  # Clean up persona language
15698
  clean_content = sanitize_persona_and_enforce_article(formatted_content)
15699
+ # Convert <br> tags to line breaks
15700
+ clean_content = re.sub(r'<br\s*/?>', '\n\n', clean_content, flags=re.IGNORECASE)
15701
+ # Extract and render markdown tables first
15702
+ clean_content = _extract_and_render_markdown_tables(clean_content)
15703
  # Normalize markdown formatting
15704
  normalized_content = normalize_markdown_block_for_step3(clean_content)
15705
  st.markdown(f"### 📋 {t('detailed_analysis', 'Detailed Analysis')}")
15706
+ # Split into paragraphs and display
15707
+ paragraphs = normalized_content.split('\n\n') if '\n\n' in normalized_content else [normalized_content]
15708
+ for paragraph in paragraphs:
15709
+ if paragraph.strip():
15710
+ # Check if it contains markdown formatting
15711
+ if any(token in paragraph for token in ['\n- ', '\n* ', '\n1.', '\n2.', '### ', '#### ', '**']):
15712
+ st.markdown(paragraph)
15713
+ else:
15714
+ st.markdown(
15715
+ f'<div style="margin-bottom: 18px; padding: 15px; background: linear-gradient(135deg, #ffffff, #f8f9fa); border: 1px solid #e9ecef; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">'
15716
+ f'<p style="margin: 0; line-height: 1.8; font-size: 16px; color: #2c3e50;">{paragraph.strip()}</p>'
15717
+ f'</div>',
15718
+ unsafe_allow_html=True
15719
+ )
15720
  st.markdown("")
15721
  return # Exit early to avoid showing duplicate content
15722
  except Exception:
 
16139
 
16140
  # Only display if content remains after filtering
16141
  if detailed_text.strip():
16142
+ # Convert <br> tags to line breaks
16143
+ detailed_text = re.sub(r'<br\s*/?>', '\n\n', detailed_text, flags=re.IGNORECASE)
16144
+ # Extract and render markdown tables first
16145
+ detailed_text = _extract_and_render_markdown_tables(detailed_text)
16146
  st.markdown(f"#### 📋 {t('detailed_analysis', 'Detailed Analysis')}")
16147
+ # Split into paragraphs and display
16148
+ paragraphs = detailed_text.split('\n\n') if '\n\n' in detailed_text else [detailed_text]
16149
+ for paragraph in paragraphs:
16150
+ if paragraph.strip():
16151
+ # Check if it contains markdown formatting or tables
16152
+ if any(token in paragraph for token in ['\n- ', '\n* ', '\n1.', '\n2.', '### ', '#### ', '**', '<table']):
16153
+ st.markdown(paragraph, unsafe_allow_html=True)
16154
+ else:
16155
+ st.markdown(
16156
+ f'<div style="margin-bottom: 20px; padding: 20px; background: linear-gradient(135deg, #ffffff, #f8f9fa); border: 1px solid #e9ecef; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.08);">'
16157
+ f'<div style="color: #2c3e50; line-height: 1.7;">{paragraph.strip()}</div>'
16158
+ f'</div>',
16159
+ unsafe_allow_html=True
16160
+ )
16161
 
16162
  # Nuclear option: remove any Economic Analysis with braces
16163
  if re.search(r"Economic Analysis:\s*\{", detailed_text, re.IGNORECASE):
 
16198
  )
16199
 
16200
  detailed_text = sanitize_persona_and_enforce_article(detailed_text)
16201
+
16202
+ # Convert <br> tags to line breaks
16203
+ detailed_text = re.sub(r'<br\s*/?>', '\n\n', detailed_text, flags=re.IGNORECASE)
16204
+
16205
+ # Extract and render markdown tables first
16206
+ detailed_text = _extract_and_render_markdown_tables(detailed_text)
16207
 
16208
  # Process HTML/XML tables in the content first
16209
  processed_text = process_html_tables(detailed_text)