DanielCL commited on
Commit
10afe3a
1 Parent(s): fd07604

fixed the error when paragraph above the image link has white spaces

Browse files

at line 27, I have added patterns for white spaces at the end of the previous paragraph: `[\s]+]?`

Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -15,13 +15,16 @@ def fix_imgs(src, dst):
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"""
 
15
  return re.sub(r'!\[\[([^.]+)\.\w+(\|\d+)?\]\]', repl_img, dst)
16
 
17
  def fix_imgs_with_hide(src, dst):
18
+ if dst != "":
19
+ result_no_hide = fix_imgs(src, dst)
20
+ else:
21
+ result_no_hide = src
22
 
23
  def add_hide_top_func(x):
24
  add_hide_top = """\n\n[details='Images']"""
25
  return f'{x.group(1)}{add_hide_top}{x.group(2)}'
26
 
27
+ result_top_hide = re.sub(r'([\.|\?|\w|\`][\s]+]?)([\n]+!\[[^|]+\|\S+\]\(\S+\))', add_hide_top_func, result_no_hide)
28
 
29
  def add_hide_bottom_func(x):
30
  add_hide_bottom = """[/details]\n\n"""