update hidden word handling
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import os
|
|
| 8 |
from typing import Optional, List
|
| 9 |
import string
|
| 10 |
import random
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def extract_text_from_pptx(file_path):
|
|
@@ -122,23 +123,29 @@ def handle_json_output(json_list : list) :
|
|
| 122 |
random_string1 = generate_random_string()
|
| 123 |
random_string2 = generate_random_string()
|
| 124 |
element = json_list[i]
|
|
|
|
|
|
|
| 125 |
element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 126 |
-
f'<p>{
|
| 127 |
element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 128 |
-
f'<p>{
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
# element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 135 |
-
# f'<p>{element["backText"]}</p></div>')
|
| 136 |
-
# # last item on the list
|
| 137 |
-
else:
|
| 138 |
element["termType"] = "cloze"
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
return json_list
|
| 143 |
|
| 144 |
|
|
|
|
| 8 |
from typing import Optional, List
|
| 9 |
import string
|
| 10 |
import random
|
| 11 |
+
import re
|
| 12 |
|
| 13 |
|
| 14 |
def extract_text_from_pptx(file_path):
|
|
|
|
| 123 |
random_string1 = generate_random_string()
|
| 124 |
random_string2 = generate_random_string()
|
| 125 |
element = json_list[i]
|
| 126 |
+
front = element["frontText"]
|
| 127 |
+
back = element["backText"]
|
| 128 |
element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 129 |
+
f'<p>{front}</p></div>')
|
| 130 |
element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 131 |
+
f'<p>{back}</p></div>')
|
| 132 |
+
element["termType"] = "basic"
|
| 133 |
+
cloze_matches = re.findall(r'_{2,}', front)
|
| 134 |
+
# match only the first one, if there is multiple don't do anything
|
| 135 |
+
if cloze_matches != [] & len(cloze_matches != 2):
|
| 136 |
+
# It's a cloze type card
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
element["termType"] = "cloze"
|
| 138 |
+
# inject the back in a span format into the front
|
| 139 |
+
def replace_cloze(match):
|
| 140 |
+
return f'</p><p><span class="closure">{back}</span></p><p>'
|
| 141 |
+
front = re.sub(r'_{2,}', replace_cloze, front)
|
| 142 |
+
# update
|
| 143 |
+
element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 144 |
+
f'<p>{front}</p></div>')
|
| 145 |
+
element["backText"] = ""
|
| 146 |
+
element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
|
| 147 |
+
f'<p><br></p></div>')
|
| 148 |
+
|
| 149 |
return json_list
|
| 150 |
|
| 151 |
|