check: Protected quotes and bcodes (+stats) in main fonction protect_bcodes_quotes()

This commit is contained in:
Cyrille L 2023-01-03 14:07:28 +01:00
parent 6877d67533
commit 739236bc47
1 changed files with 49 additions and 65 deletions

View File

@ -345,88 +345,72 @@ def protect_icodes(post_bottom, article_bottom):
def protect_bcodes_quotes(process, post_bottom, article_bottom):
global protect_article
global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB
in_bcode = in_quote = False
protect_article = ''
temp_article = article_bottom
nbr_titles = nbr_bcodes = nbr_quotes = 0
bcode = quote = ''
end_bcode = end_quote = False
if process == 'check':
global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB
nbr_titles = nbr_bcodes = nbr_quotes = 0
for line in post_bottom:
for line in post_bottom:
# Bcode
if not in_quote:
if line.startswith(words_tags[12][0]):
in_bcode = True
nbr_bcodes += 1
continue
if process == 'check':
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
nbr_bcodes += 1
elif line.startswith(words_tags[12][1]):
in_bcode = False
continue
elif line.startswith('#'): # As convention
if line.startswith(titles_tags): nbr_titles += 1
else: continue
if in_bcode: continue
elif line.startswith(words_tags[11][0]):
in_quote = True
nbr_quotes += 1
continue
elif line.startswith(words_tags[11][1]):
in_quote = False
continue
if in_quote:
if not line in (words_tags[10][0], words_tags[10][1]):
continue
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
# For wip, bcodes are converted to base64
#----------------------------------------
elif process == 'wip':
bcode = quote = ''
end_bcode = end_quote = False
for line in post_bottom:
# Bcode
if not in_quote:
if line.startswith(words_tags[12][0]):
in_bcode = True
elif line.startswith(words_tags[12][1]):
if process == "wip":
bcode = '%s\n%s'%(bcode, line)
b64_bcode = b64('Encode', bcode, 'B64.', '.B64')
line = b64_bcode
end_bcode = True
in_bcode = False
in_bcode = False
# Quote
if not in_bcode:
if line.startswith(words_tags[11][0]):
in_quote = True
elif line.startswith(words_tags[11][1]):
# Quote
if not in_bcode:
if line.startswith(words_tags[11][0]):
in_quote = True
if process == 'check':
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
nbr_quotes += 1
elif line.startswith(words_tags[11][1]):
if process == "wip":
quote = '%s\n%s'%(quote, line)
b64_quote = b64('Encode', quote, 'Q64.', '.Q64')
line = b64_quote
end_quote = True
in_quote = False
in_quote = False
if in_bcode:
if not bcode: bcode = line
else: bcode = '%s\n%s'%(bcode, line)
# Count titles for check
# Pass if line is a comment
if not in_bcode or not in_quote:
if line.startswith(titles_tags):
if process == 'check':
nbr_titles += 1
elif line.startswith('#'):
continue
elif in_quote:
if not quote: quote = line
else: quote = '%s\n%s'%(quote, line)
if in_bcode:
if not bcode: bcode = line
else: bcode = '%s\n%s'%(bcode, line)
if end_bcode: bcode = ''; end_bcode = False ; in_bcode = False
elif end_quote: quote = ''; end_quote = False ; in_quote = False
elif in_quote:
if not quote: quote = line
else: quote = '%s\n%s'%(quote, line)
if in_quote or in_bcode:
continue
else:
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
if end_bcode: bcode = ''; end_bcode = False ; in_bcode = False
elif end_quote: quote = ''; end_quote = False ; in_quote = False
if in_quote or in_bcode:
continue
else:
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
#=====================================#