wip: fix quotes. Added pre-tabs for html article

This commit is contained in:
Cyrille L 2022-12-31 15:47:14 +01:00
parent 93b9fc7a2e
commit 6983ea89ed
1 changed files with 57 additions and 10 deletions

View File

@ -91,6 +91,7 @@ def wip_article(target):
wip_icodes() # inline_codes. Decode base64 icode and replace
wip_bcodes() # Block-codes. Decode B64 and convert to HTML
wip_raws(target) # Read file and convert to HTML
wip_tabs() # make HTML tabulations
# Result (temp display)
print(article_bottom)
@ -311,6 +312,7 @@ def wip_quotes() :
# Read the quote. Get parameters
author = date = lang = book = link = quote_html = ''
cite = figc = ''
tab_t = ''
tab_p = tab_c = 2 # Init 2 tabs after <blockquote>
auth_html = title_html = ''
@ -383,9 +385,13 @@ def wip_quotes() :
else:
title_html = ' title="%s"'%author
auth_html = '%s'%author
if link: figc= '<a class="figc" href="%s">%s</a>'%(
link, auth_html
)
else:
figc = '<span class="figc">%s</span>'%auth_html
else:
if book and date: title_html = ' title="%s (%s)"'%(
book, date
@ -395,8 +401,9 @@ def wip_quotes() :
time_html_o = time_html_c = ''
if date:
time_html_o = '<time datetime="%s">\n'%date
time_html_c = '</time>\n'
if author: tab_t = ' '
time_html_o = '%s<time datetime="%s">\n'%(tab_t, date)
time_html_c = '%s</time>\n'%tab_t
# Create HTML Quote with datas
if author:
@ -404,9 +411,9 @@ def wip_quotes() :
' <blockquote class="%s"%s%s%s>\n'%(
set_css, lang, cite, title_html
) + \
' ' + time_html_o + \
time_html_o + \
'%s\n'%quote_html + \
' ' + time_html_c + \
time_html_c + \
' </blockquote>\n' + \
' <figcaption class="%s">\n'%set_css + \
' %s\n'%figc + \
@ -521,15 +528,17 @@ def wip_titles():
article_tmp2 = article_temp
indiv = False
for ln, line in enumerate(article_tmp2.rsplit('\n')):
try: article_tmp2.rsplit('\n')[ln + 1]
except: continue
if line.startswith('<h') and indiv:
article_temp = article_temp.replace(
line, '</div>\n%s'%line
)
indiv = False
if line.startswith('<h'):
try: article_tmp2.rsplit('\n')[ln + 1]
except: continue
#if line.startswith('<h'):
if article_tmp2.rsplit('\n')[ln + 1].startswith('<div'):
indiv = True
@ -542,9 +551,9 @@ def wip_titles():
article_bottom = article_temp
#
# Convert raw file to HTML with <pre> + <code>
#
#==============================================#
# Convert raw file to HTML with <pre> + <code> #
#----------------------------------------------#
def wip_raws(target):
if uniq_raws == 0: return
@ -568,3 +577,41 @@ def wip_raws(target):
article_bottom = article_bottom.replace(
eval(raw)[0], raw_html
)
#
# Make HTML tabulations
#
def wip_tabs():
global article_bottom
article_temp = ''
tab_start = 8 # From <article> tag
indiv = False
for line in article_bottom.rsplit('\n'):
# Titles
if line.startswith('<h'):
get_tab = line[2]
tab = int(tab_start) + 2 * int(get_tab)
if not article_temp: article_temp = '%s%s'%(tab * ' ', line)
else: article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line)
continue
# div
if line.startswith('<div'):
tab = int(tab) + 2
indiv = True
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line)
tab = int(tab) + 2
continue
elif line.startswith('</div>'):
tab = int(tab) - 2
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line)
indiv = False
continue
# Other contents
else:
article_temp = '%s\n%s%s'%(article_temp, tab * ' ', line)
article_bottom = article_temp