Better HTML tabulations

This commit is contained in:
Cyrille L 2023-01-17 16:20:43 +01:00
parent 60079467f6
commit 8b00709200
1 changed files with 18 additions and 8 deletions

View File

@ -628,34 +628,44 @@ def wip_raws(target):
def wip_tabs(): def wip_tabs():
global article_bottom global article_bottom
article_temp = '' article_temp = ''
tab = tab_start = 2 # From <article> tag tab = tab_start = 6 # From <article> tag
indiv = False indiv = False
tabs_hX = {
'1' : '6',
'2' : '8',
'3' : '10',
'4' : '12',
'5' : '14',
'6' : '16'
}
for line in article_bottom.rsplit('\n'): for line in article_bottom.rsplit('\n'):
# Titles # Titles
if line.startswith('<h'): if line.startswith('<h'):
get_tab = line[2] get_tab = line[2]
tab = int(tab_start) + 2 * int(get_tab) tab = tabs_hX[get_tab]
if not article_temp: article_temp = '%s%s'%(tab * ' ', line) if not article_temp: article_temp = '%s%s'%(int(tab) * ' ', line)
else: article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line) else: article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
continue continue
# div # div
if line.startswith('<div'): if line.startswith('<div'):
tab = int(tab) + 2 tab = int(tab) + 2
indiv = True indiv = True
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line) article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
tab = int(tab) + 2 tab = int(tab) + 2
continue continue
elif line.startswith('</div>'): elif line.startswith('</div>'):
tab = int(tab) - 2 tab = int(tab) - 2
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line) article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
indiv = False indiv = False
continue continue
# Other contents # Other contents
else: else:
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line) if not article_temp: article_temp = '%s%s'%(int(tab) * ' ', line)
else: article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
article_bottom = article_temp article_bottom = article_temp