Mark7549 commited on
Commit
b9f1e11
·
1 Parent(s): 7eeaa6b

improved spacing in dictionary

Browse files
Files changed (1) hide show
  1. lsj_dict.py +7 -5
lsj_dict.py CHANGED
@@ -150,6 +150,8 @@ def format_text(data):
150
  pattern = r"\s+([,;:.()\"\'\[\]])\s+"
151
  text = re.sub(pattern, r"\1 ", text)
152
 
 
 
153
  # .replace(",", ", ").replace(";", "; ").replace(":", ": ").replace("(", " (").replace(")", ") ").replace("[", " [").replace("]", "] ").replace(" ,", ", ").replace(" ; ", "; ").replace(" : ", ": ").replace(" ." , ". ")
154
 
155
  formatted_text = []
@@ -172,7 +174,7 @@ def format_text(data):
172
  "u", "v", "w", "x", "y", "z"
173
  ]
174
 
175
- header = text.split("\n")[0]
176
  formatted_text.append(header)
177
 
178
  for text_part in text.split("[SENSE_SEPARATOR]")[1:]:
@@ -182,13 +184,13 @@ def format_text(data):
182
  if level == "A":
183
  formatted_text.append(f"<div class='list-class primary-class'> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
184
  elif level in secondary_indicators:
185
- formatted_text.append(f"<div class='list-class secondary-class'><span class='secondary-indicator'>{level}.</span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
186
  elif level in tertiary_indicators:
187
- formatted_text.append(f"<div class='list-class tertiary-class'> <span class='tertiary-indicator'>{level}.</span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
188
  elif level in quaternary_indicators:
189
- formatted_text.append(f"<div class='list-class quaternary-class'> <span class='quaternary-indicator'>{level}.</span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div> ")
190
  elif level in primary_indicators:
191
- formatted_text.append(f"<div class='list-class primary-class'> <span class='primary-indicator'>{level}.</span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
192
 
193
  return '\n'.join(formatted_text)
194
 
 
150
  pattern = r"\s+([,;:.()\"\'\[\]])\s+"
151
  text = re.sub(pattern, r"\1 ", text)
152
 
153
+ pattern_2 = r"(\S),(\S)"
154
+ text = re.sub(pattern_2, r"\1, \2", text)
155
  # .replace(",", ", ").replace(";", "; ").replace(":", ": ").replace("(", " (").replace(")", ") ").replace("[", " [").replace("]", "] ").replace(" ,", ", ").replace(" ; ", "; ").replace(" : ", ": ").replace(" ." , ". ")
156
 
157
  formatted_text = []
 
174
  "u", "v", "w", "x", "y", "z"
175
  ]
176
 
177
+ header = text.split("\n\n[SENSE_SEPARATOR]")[0]
178
  formatted_text.append(header)
179
 
180
  for text_part in text.split("[SENSE_SEPARATOR]")[1:]:
 
184
  if level == "A":
185
  formatted_text.append(f"<div class='list-class primary-class'> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
186
  elif level in secondary_indicators:
187
+ formatted_text.append(f"<div class='list-class secondary-class'><span class='secondary-indicator'>{level}. </span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
188
  elif level in tertiary_indicators:
189
+ formatted_text.append(f"<div class='list-class tertiary-class'> <span class='tertiary-indicator'>{level}. </span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
190
  elif level in quaternary_indicators:
191
+ formatted_text.append(f"<div class='list-class quaternary-class'> <span class='quaternary-indicator'>{level}. </span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div> ")
192
  elif level in primary_indicators:
193
+ formatted_text.append(f"<div class='list-class primary-class'> <span class='primary-indicator'>{level}. </span> {text_part.replace('[SENSE_SEPARATOR]', '')} </div>")
194
 
195
  return '\n'.join(formatted_text)
196