Spaces:
Runtime error
Runtime error
add hide button to the `fix_imgs` function into a new function `fix_imgs_with_hide` (#2)
Browse files- add hide button to the `fix_imgs` function into a new function `fix_imgs_with_hide` (5376226a451e4c4afbbe6791180c203c19d5ebfe)
Co-authored-by: Liao <[email protected]>
app.py
CHANGED
@@ -13,5 +13,20 @@ def fix_imgs(src, dst):
|
|
13 |
else: return f'MISSING IMAGE: {x.group(1)}'
|
14 |
|
15 |
return re.sub(r'!\[\[([^.]+)\.\w+(\|\d+)?\]\]', repl_img, dst)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
gr.Interface(fn=
|
|
|
13 |
else: return f'MISSING IMAGE: {x.group(1)}'
|
14 |
|
15 |
return re.sub(r'!\[\[([^.]+)\.\w+(\|\d+)?\]\]', repl_img, dst)
|
16 |
+
|
17 |
+
def fix_imgs_with_hide(src, dst):
|
18 |
+
result_no_hide = fix_imgs(src, dst)
|
19 |
+
|
20 |
+
def add_hide_top_func(x):
|
21 |
+
add_hide_top = """\n\n[details='Images']"""
|
22 |
+
return f'{x.group(1)}{add_hide_top}{x.group(2)}'
|
23 |
+
|
24 |
+
result_top_hide = re.sub(r'(\w|\?|\.|\`)([\n]+!\[[^|]+\|\S+\]\(\S+\))', add_hide_top_func, result_no_hide)
|
25 |
+
|
26 |
+
def add_hide_bottom_func(x):
|
27 |
+
add_hide_bottom = """[/details]\n\n"""
|
28 |
+
return f'{x.group(1)}{add_hide_bottom}{x.group(2)}'
|
29 |
+
|
30 |
+
return re.sub(r'(!\[[^|]+\|\S+\]\(\S+\)[\n]+)(\w|#)', add_hide_bottom_func, result_top_hide)
|
31 |
|
32 |
+
gr.Interface(fn=fix_imgs_with_hide, inputs=[gr.Textbox(lines=15),gr.Textbox(lines=15)], outputs=gr.Textbox(lines=15)).launch()
|