wip: Added module titles (remove empty lines, create divs if contents after title)

This commit is contained in:
Cyrille L 2022-12-30 17:19:20 +01:00
parent ba052211ca
commit b72a1133f6
1 changed files with 56 additions and 5 deletions

View File

@ -86,6 +86,7 @@ def wip_article(target):
wip_words_tags() # Paragraphs, strongs, italics wip_words_tags() # Paragraphs, strongs, italics
wip_links() # Links_%i from headers in DB wip_links() # Links_%i from headers in DB
wip_images() # Images_%i from headers in DB wip_images() # Images_%i from headers in DB
wip_titles()
# Quotes. Decode base64 Q64 and convert to HTML # Quotes. Decode base64 Q64 and convert to HTML
wip_quotes() wip_quotes()
@ -454,18 +455,15 @@ def wip_bcodes():
# Convert src_bcode # Convert src_bcode
for line in src_bcode.rsplit('\n'): for line in src_bcode.rsplit('\n'):
# CSS + opened marker # CSS + opened marker
if line.startswith(tyto.words_tags[12][0]): if line.startswith(tyto.words_tags[12][0]):
set_css = tyto.get_css(line) set_css = tyto.get_css(line)
html_bcode = '<pre class="%s">\n'%set_css + \ html_bcode = '<pre class="%s">\n'%set_css + \
' <code class="bcode">' ' <code class="bcode">'
# closed marker # closed marker
elif line.startswith(tyto.words_tags[12][1]): elif line.startswith(tyto.words_tags[12][1]):
html_bcode = '%s\n </code>\n'%html_bcode + \ html_bcode = '%s\n </code>\n'%html_bcode + \
'</pre>' '</pre>'
# Block-code content per line # Block-code content per line
else: else:
html_bcode = '%s\n <span class="bcode">%s</span>'%(html_bcode, line) html_bcode = '%s\n <span class="bcode">%s</span>'%(html_bcode, line)
@ -473,5 +471,58 @@ def wip_bcodes():
article_bottom = article_bottom.replace(rep_bcode, html_bcode) article_bottom = article_bottom.replace(rep_bcode, html_bcode)
#========================================#
# Convert titles to HTML #
# Check between titles to set div or not #
#----------------------------------------#
def wip_titles():
global article_bottom
article_temp = article_bottom
article_tmp2 = '' # COnstruct article, without empty lines
for line in article_bottom.rsplit('\n'):
if line.startswith('#'):
hx = line[1]
title_cont = line[2: len(line)].lstrip()
title_html = '<h%s class="title_%s">%s</h%s>'%(hx, hx, title_cont, hx)
article_temp = article_temp.replace(line, title_html)
# Remove useless empty lines from article
for line in article_temp.rsplit('\n'):
if line:
if article_tmp2: article_tmp2 = '%s\n%s'%(article_tmp2, line)
else: article_tmp2 = line
article_temp = article_tmp2
# Add div after title if needed
for ln, line in enumerate(article_tmp2.rsplit('\n')):
if line.startswith('<h'):
if article_tmp2.rsplit('\n')[ln + 1].startswith('<h'):
continue
else:
article_temp = article_temp.replace(
line, '%s\n<div class="content_title">'%line
)
article_tmp2 = article_temp
# Add div after title if needed
indiv = False
for ln, line in enumerate(article_tmp2.rsplit('\n')):
if line.startswith('<h') and \
article_tmp2.rsplit('\n')[ln + 1].startswith('<div'):
indiv = True
elif line.startswith('<h') and indiv:
article_temp = article_temp.replace(
line, '</div>\n%s'%line
)
indiv = False
if indiv:
article_temp = '%s\n</div>'%article_temp
# Replace article with new contents
article_bottom = article_temp