Spaces:
Runtime error

dhruv575 commited on
Commit
656f1ea
·
1 Parent(s): f0a2332

Save the divider

Browse files
Files changed (1) hide show
  1. app/email_new_converter.py +27 -7
app/email_new_converter.py CHANGED
@@ -646,13 +646,28 @@ class EmailNewConverter:
646
  margin_bottom = "0"
647
 
648
  # Try to extract border-top color
649
- border_match = re.search(r'border-top\s*:\s*[^;]+', hr_style, re.IGNORECASE)
 
650
  if border_match:
651
- border_value = border_match.group(0)
652
- # Try to extract color from border-top value
653
- color_match = re.search(r'#[\da-fA-F]{3,6}|\w+', border_value)
654
- if color_match:
655
- border_color = color_match.group(0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
 
657
  # Try to extract margin values
658
  margin_match = re.search(r'margin\s*:\s*([^;]+)', hr_style, re.IGNORECASE)
@@ -680,7 +695,12 @@ class EmailNewConverter:
680
  td = soup.new_tag("td")
681
  td["style"] = f"padding:0;border-top:1px solid {border_color};"
682
  # Add a non-breaking space to prevent email clients from collapsing the empty cell
683
- td.append("\u00A0") # Non-breaking space
 
 
 
 
 
684
  tr.append(td)
685
 
686
  # Replace hr with the table
 
646
  margin_bottom = "0"
647
 
648
  # Try to extract border-top color
649
+ # Look for border-top style specifically
650
+ border_match = re.search(r'border-top\s*:\s*([^;]+)', hr_style, re.IGNORECASE)
651
  if border_match:
652
+ border_value = border_match.group(1).strip() # Get the value part after the colon
653
+ # Extract hex color (most common case: "1px solid #F3F4F6")
654
+ hex_color_match = re.search(r'#[\da-fA-F]{3,6}', border_value)
655
+ if hex_color_match:
656
+ border_color = hex_color_match.group(0)
657
+ else:
658
+ # Fallback: extract the last token that looks like a color
659
+ # Split by spaces and take the last non-keyword token
660
+ tokens = border_value.split()
661
+ # CSS keywords to skip
662
+ skip_tokens = {'solid', 'dashed', 'dotted', 'double', 'groove', 'ridge', 'inset', 'outset',
663
+ 'px', 'em', 'rem', 'pt', '1px', '2px', '3px', 'thin', 'medium', 'thick'}
664
+ for token in reversed(tokens):
665
+ token_clean = token.rstrip(';').lower()
666
+ if token_clean not in skip_tokens and token_clean:
667
+ # If it's not a number and not a keyword, assume it's a color
668
+ if not token_clean.replace('.', '').isdigit():
669
+ border_color = token_clean
670
+ break
671
 
672
  # Try to extract margin values
673
  margin_match = re.search(r'margin\s*:\s*([^;]+)', hr_style, re.IGNORECASE)
 
695
  td = soup.new_tag("td")
696
  td["style"] = f"padding:0;border-top:1px solid {border_color};"
697
  # Add a non-breaking space to prevent email clients from collapsing the empty cell
698
+ # BeautifulSoup will automatically escape this, but we want the entity
699
+ # So we'll set it as raw HTML after creation
700
+ from bs4 import NavigableString
701
+ # Create a NavigableString with the entity - BeautifulSoup will preserve it
702
+ nbsp = NavigableString("\u00A0") # Non-breaking space Unicode
703
+ td.append(nbsp)
704
  tr.append(td)
705
 
706
  # Replace hr with the table