Lots of changes. Need tests, but should work

This commit is contained in:
Cyrille L 2023-03-10 12:17:45 +01:00
parent 43895adef7
commit 6671b03e95
5 changed files with 349 additions and 286 deletions

View File

@ -54,6 +54,7 @@ pass_db = \
'edit-wip',
'edit-www',
'publish',
'show',
'show-db',
'show-wip',
'show-www',

View File

@ -35,7 +35,7 @@ def manage_check(target):
# target needed
if not target: logs.out("5", '', True)
global date_wip, hash_wip, date_www, hash_www
global date_wip, hash_wip, date_www, hash_www, post_bottom
date_wip = hash_wip = date_www = hash_www = ''
# Article has DB
@ -100,26 +100,28 @@ def manage_check(target):
file_to_string(db.uri_file)
# Specific to inline-code: check markers on same line
check_icodes(article.rsplit('\n'))
# Protect inline-codes
tyto.protect_icodes(post_bottom, article_bottom)
post_bottom = tyto.protect_article.rsplit('\n')
article_bottom = tyto.protect_article
if_icodes_bcodes_quotes(post_bottom)
# Protect block-codes and quotes
tyto.protect_bcodes_quotes('check', post_bottom, article_bottom)
post_bottom = tyto.protect_article.rsplit('\n')
article_bottom = tyto.protect_article
if bcode or quote:
tyto.protect_bcodes_quotes('check', post_bottom)
post_bottom = tyto.protect_article
# Protect inline-codes
if icode:
tyto.protect_icodes(post_bottom)
post_bottom = tyto.protect_article
# Count words in article. Quotes, block-codes, icode = 1 per each
post_words = len(article_bottom.strip().split(" "))
post_words = len(post_bottom.strip().split(" "))
# Check for valid contents
check_content(post_bottom)
post_bottom = article_bottom.rsplit('\n')
post_bottom = post_bottom.rsplit('\n')
check_headers(post_header)
#post_header = post_header.rsplit('\n')
check_headers(post_header.rsplit('\n'))
# Exit if unused needed tags
if post_err:
@ -131,62 +133,81 @@ def manage_check(target):
create_database()
#=====================#
# Find in post_bottom #
#---------------------#
def isin(term, post_bottom):
for x in post_bottom:
if re.search(r'%s'%term, x):
return True
return False
#=================================#
# Create string article from file #
# Check if separator or exit #
#---------------------------------#
def file_to_string(post_file):
global article
global article_header, article_bottom
global post_header, post_bottom
post_header = post_bottom = ''
sep = False
article = open(post_file, 'r').read()
for line in article.rsplit('\n'):
if line.startswith('-----'):
sep = True
continue
if sep:
if not post_bottom: post_bottom = line
else: post_bottom = '%s\n%s'%(post_bottom, line)
else:
if not post_header: post_header = line
else: post_header = '%s\n%s'%(post_header, line)
# Check if separator or exit
if not '-----' in article: logs.out("6", '-----', True)
# Set from separator, NOT splitted by new line
article_header = article.rsplit('-----')[0]
article_bottom = article.rsplit('-----')[1]
# Set from separator, splitted by new line
post_header = article.rsplit('-----')[0].rsplit('\n')
post_bottom = article.rsplit('-----')[1].rsplit('\n')
if not sep:
logs.out("6", '-----', True)
#=============================================#
# Check if bcodes and quotes #
# Check inline code, for markers on same line #
# Stats for titles, quotes, bcodes, uniq_ancs #
#---------------------------------------------#
def check_icodes(article):
quote = bcode = False
def if_icodes_bcodes_quotes(post_bottom):
global icode, quote, bcode
global nbr_titles, nbr_quotes, nbr_bcodes, nbr_ancs
icode = quote = in_quote = bcode = in_bcode = False
nbr_titles = nbr_quotes = nbr_bcodes = nbr_ancs = 0
for ln, line in enumerate(article, 1):
icode_m1 = icode_m2 = 0
# Pass Comments
if line.startswith('#'): continue
for ln, line in enumerate(post_bottom.rsplit('\n'), 1):
# Pass Comments, count titles
# Count titles
if not line:
continue
elif line.startswith(tyto.titles_tags):
nbr_titles += 1
continue
elif line.startswith('#'):
continue
# Pass quotes
if line.startswith(tyto.words_tags[11][0]): quote = True
if line.startswith(tyto.words_tags[11][1]): quote = False
elif line.startswith(tyto.words_tags[11][0]) and not in_bcode:
quote = in_quote = True
nbr_quotes += 1
continue
elif line.startswith(tyto.words_tags[11][1]):
in_quote = False
continue
# Pass bcode
if line.startswith(tyto.words_tags[12][0]): bcode = True
if line.startswith(tyto.words_tags[12][1]): bcode = False
elif line.startswith(tyto.words_tags[12][0]) and not in_quote:
bcode = in_bcode = True
nbr_bcodes += 1
continue
elif line.startswith(tyto.words_tags[12][1]):
in_bcode = False
continue
if bcode or quote: continue
if tyto.words_tags[9][0] or tyto.words_tags[9][1] in line:
if in_bcode or in_quote:
continue
elif line.startswith(tyto.single_tags[1][0]):
nbr_ancs += 1
elif tyto.words_tags[9][0] or tyto.words_tags[9][1] in line:
icode_m1 = icode_m2 = 0
icode_m1 = line.count(tyto.words_tags[9][0])
icode_m2 = line.count(tyto.words_tags[9][1])
if icode_m1 != icode_m2:
@ -194,6 +215,8 @@ def check_icodes(article):
tyto.words_tags[9][0], tyto.words_tags[9][1]
), True
)
else:
icode = True
#==================================#
@ -226,7 +249,6 @@ def check_headers(post_header):
# Read articles lines, till separator #
#-------------------------------------#
for ln, line in enumerate(post_header, 1):
# Set each needed tag #
# Only the first one is set #
#---------------------------#
@ -283,7 +305,7 @@ def check_headers(post_header):
# Check if set needed tags
for tag in need_headers:
if not need_headers[tag]:
logs_out("6", tag, False)
logs.out("6", tag, False)
post_err = True
@ -573,7 +595,6 @@ def check_file_uri(filetype, filename, ln):
#---------------------------#
def check_content(post_bottom):
global post_err
global article_bottom
# Check tags for words (strongs, italics...)
# Set stats for each one
@ -582,13 +603,13 @@ def check_content(post_bottom):
c_opened = c_closed = 0
if tag[5] == 'w':
c_opened = article_bottom.count(tag[0])
c_closed = article_bottom.count(tag[1])
c_opened = post_bottom.count(tag[0])
c_closed = post_bottom.count(tag[1])
# Useless tag now, replace
article_bottom = article_bottom.replace(tag[0], '')
article_bottom = article_bottom.replace(tag[1], '')
post_bottom = post_bottom.replace(tag[0], '')
post_bottom = post_bottom.replace(tag[1], '')
elif tag[5] == 't':
for line in post_bottom:
for line in post_bottom.rsplit('\n'):
if line.startswith(tag[0]): c_opened += 1
if line.startswith(tag[1]): c_closed += 1
@ -603,11 +624,8 @@ def check_content(post_bottom):
# Check if anchor has target
# Count anchors target
#---------------------------
global stat_ancs
stat_ancs = 0
for line in post_bottom:
if line.startswith(tyto.single_tags[1][0]): stat_ancs += 1
for line in post_bottom.rsplit('\n'):
# Anchor link
if tyto.words_tags[0][0] and tyto.words_tags[0][1] in line:
anchors = re.findall(r">_(.*?)_<", line)
for anchor in anchors:
@ -617,6 +635,16 @@ def check_content(post_bottom):
logs.out("6", 'anchor, %s'%tag, False)
post_err = True
# Anchor source "->"
elif line.startswith(tyto.single_tags[1][0]):
set_css = tyto.get_css(line)
is_uniq_anchor = "%s %s"%(tyto.single_tags[1][0], set_css)
c_uniq_anchor = post_bottom.count(is_uniq_anchor)
if c_uniq_anchor > 1:
logs.out("15", '%s "%s"'%(c_uniq_anchor, is_uniq_anchor), False)
post_err = True
break
# Lists: check if contents are valid
#-----------------------------------
@ -663,8 +691,8 @@ def check_content(post_bottom):
# Template Tags (warning for not paired symbols)
#-----------------------------------------------
for tag in tyto.tpl_tags:
tpl1 = article_bottom.count(tag[0])
tpl2 = article_bottom.count(tag[1])
tpl1 = post_bottom.count(tag[0])
tpl2 = post_bottom.count(tag[1])
if tpl1 != tpl2:
logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False)
@ -735,7 +763,7 @@ def create_database():
)
db_stats = '\n# Statistics from optional tags\n' + \
'uniq_anchors = %d\n'%stat_ancs + \
'uniq_anchors = %d\n'%nbr_ancs + \
'uniq_abbrs = %d\n'%stat_abbrs + \
'uniq_links = %d\n'%stat_links + \
'uniq_images = %d\n'%stat_images + \
@ -744,7 +772,7 @@ def create_database():
'\n# Statistics from post content\n' + \
'stat_tags = %d\n'%post_tags + \
'stat_words = %d\n'%post_words + \
'stat_titles = %d\n'%tyto.nbr_titles + \
'stat_titles = %d\n'%nbr_titles + \
'stat_paragraphs = %d\n'%post_paragraphs + \
'stat_anchors = %d\n'%post_anchors + \
'stat_strongs = %d\n'%post_strongs + \
@ -756,10 +784,23 @@ def create_database():
'stat_cites = %d\n'%post_cites + \
'stat_customs = %d\n'%post_customs + \
'stat_icodes = %d\n'%tyto.nbr_icodes + \
'stat_bcodes = %d\n'%tyto.nbr_bcodes + \
'stat_quotes = %d\n'%tyto.nbr_quotes + \
'stat_bcodes = %d\n'%nbr_bcodes + \
'stat_quotes = %d\n'%nbr_quotes + \
'stat_lists = %d\n'%post_lists
'''
'''
database = '%s\n%s'%(database, db_stats)
tyto.set_file(db.post_db, 'new', database)
logs.out("21", '', True)
#=====================#
# Find in post_bottom #
#---------------------#
def isin(term, post_bottom):
for x in post_bottom:
if re.search(r'%s'%term, x):
return True
return False

View File

@ -44,6 +44,7 @@ def out(nbr, value, out):
'12' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, CS),
'13' : ':< %sNo file or directory%s here (deleted ?)'%(CR, CS),
'14' : ':< %sMismatch%s program start'%(CR, CS),
'15' : ':< Anchor %snot uniq%s: %s'%(CR, CS, value),
'19' : ':D Article %swip%s on: %s'%(CG, CS, value),
'20' : ':D Article %scheck%s on: %s'%(CG, CS, value),
'21' : ':D Article %sValid%s. Ready to wip'%(CG, CS),

View File

@ -244,137 +244,149 @@ def get_css(line):
return set_css
#=============================================#
# First check process to protect contents #
# Protect block-Codes, quotes #
# Also remove empty/commented lines #
# Used in check and wip #
# check: create string without quotes, bcodes #
# wip: remplace quotes, bcode with base64 #
#---------------------------------------------#
def protect_bcodes_quotes(process, post_bottom):
global protect_article
global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB
in_bcode = in_quote = False
protect_article = ''
bcode = quote = '' # Only for wip process
for line in post_bottom.rsplit('\n'):
start_bcode = close_bcode = False
start_quote = close_quote = False
# Settings and counters
#----------------------
# Bcode (at close, replace with base64)
if not in_quote:
if line.startswith(words_tags[12][0]): # Open
start_bcode = True
in_bcode = True
elif line.startswith(words_tags[12][1]): # Close
close_bcode = True
in_bcode = False
if process == "wip":
bcode = '%s\n%s'%(bcode, line)
b64_bcode = b64('Encode', bcode, 'B64.', '.B64')
line = b64_bcode
# Quote (at close, replace with base64)
if not in_bcode:
if line.startswith(words_tags[11][0]): # Open
start_quote = True
in_quote = True
elif line.startswith(words_tags[11][1]): # Close
close_quote = True
in_quote = False
if process == "wip":
quote = '%s\n%s'%(quote, line)
b64_quote = b64('Encode', quote, 'Q64.', '.Q64')
line = b64_quote
if not in_quote and not in_bcode:
if not line: continue
if line.startswith('#') and not line.startswith(titles_tags):
continue
# Counters and keep tags for check process
#-----------------------------------------
if process == "check":
if in_bcode and not start_bcode \
or in_quote and not start_quote :
continue
# Set new article content for wip process
#----------------------------------------
elif process == "wip":
# bcode convertion to base64
if in_bcode:
# Convert lines to b64
if not bcode: bcode = line
else: bcode = '%s\n%s'%(bcode, line)
line = ''
elif in_quote:
# Convert lines to b64
if not quote: quote = line
else: quote = '%s\n%s'%(quote, line)
line = ''
# Set new content
#----------------
# check: remove quote/bcode, keep tags
# wip: replace close tag with quote/bcode (keep in open tag)
if not line: continue
if not protect_article: protect_article = line
else: protect_article = '%s\n%s'%(protect_article, line)
# Clean in wip process for new quote/bcode
if process == "wip":
if close_bcode: bcode = b64_bcode = ''
if close_quote: quote = b64_quote = ''
#=======================#
# Protec iCodes #
# Used in check and wip #
#-----------------------~
def protect_icodes(post_bottom, article_bottom):
def protect_icodes(post_bottom):
global protect_article
global nbr_icodes
nbr_icodes = 0 # Stats here for DB as content will change
protect_article = article_bottom
incode = False
nbr_icodes = 0 # Stats here for DB as content will change
protect_article = post_bottom
in_icode = False
src_code = rep_code = ''
# Get only lines that contains code
for ln, line in enumerate(post_bottom):
if words_tags[9][0] and words_tags[9][1] in line:
for ln, line in enumerate(post_bottom.rsplit('\n')):
if not words_tags[9][0] in line: continue
# Iterate in line
for i, c in enumerate(line):
c_b = c_bb = c_a = ""
if c == '_':
c_b = line[i-1] # before
c_bb = line[i-2] # before, before
c_a = line[i+1] # after
# Iterate (c)haracter in line
for i, c in enumerate(line):
c_b = c_bb = c_a = ""
if c == '_':
c_b = line[i-1] # before
c_bb = line[i-2] # before, before
c_a = line[i+1] # after
# incode if
if c_b == '{' and not c_bb == '\\':
incode = True
nbr_icodes += 1
code = words_tags[9][2]
continue
# incode if
if c_b == '{' and not c_bb == '\\':
in_icode = True
nbr_icodes += 1
code = words_tags[9][2]
continue
# No more in code if
if c_a == '}' and not c_b == '\\':
incode = False
code = '%s%s%s'%(code, src_code, words_tags[9][3])
b64_code = b64('Encode', code, 'I64.', '.I64')
rep_code = "%s%s%s"%(
words_tags[9][0], rep_code, words_tags[9][1]
)
temp_post = protect_article.replace(rep_code, b64_code)
protect_article = temp_post
# No more in code if
if c_a == '}' and not c_b == '\\':
in_icode = False
code = '%s%s%s'%(code, src_code, words_tags[9][3])
b64_code = b64('Encode', code, 'I64.', '.I64')
rep_code = "%s%s%s"%(
words_tags[9][0], rep_code, words_tags[9][1]
)
protect_article = protect_article.replace(rep_code, b64_code)
src_code = rep_code = b64_code = ''
continue
src_code = rep_code = b64_code = ''
continue
# Construct original replacement code and source code
if incode:
rep_code = '%s%s'%(rep_code, c)
if c == '\\': continue
src_code = '%s%s'%(src_code, c)
#=============================================#
# Protect block-Codes, quotes #
# Also remove commented lines #
# Used in check and wip #
# check: create string without quotes, bcode #
# wip: remplace quotes, bcode with base64 #
#---------------------------------------------#
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
end_bcode = end_quote = False
protect_article = ''
temp_article = article_bottom
nbr_titles = nbr_bcodes = nbr_quotes = 0
bcode = quote = ''
for line in post_bottom:
# Bcode
if not in_quote:
if line.startswith(words_tags[12][0]):
in_bcode = True
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]):
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
# 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
# Count titles for check
# Pass if line is a comment
if not in_bcode and not in_quote:
if line.startswith(titles_tags):
if process == 'check':
nbr_titles += 1
elif line.startswith('#'):
continue
if in_bcode:
if not bcode: bcode = line
else: bcode = '%s\n%s'%(bcode, line)
elif in_quote:
if line.startswith('#'): continue
if not quote: quote = line
else: quote = '%s\n%s'%(quote, 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)
# Construct original replacement code and source code
if in_icode:
rep_code = '%s%s'%(rep_code, c)
if c == '\\': continue
src_code = '%s%s'%(src_code, c)
#=====================================#

View File

@ -30,6 +30,8 @@ def manage_wip(target):
# Check if can process
domain.domain_needed()
wip_article(db.post_src)
return
# Option 'all' to wip again, based on DB
#---------------------------------------
@ -106,18 +108,19 @@ def wip_article(target):
# Convert file to strings
file_to_string(target)
global post_header, article_header
global post_bottom, article_bottom
global post_header
global post_bottom
# Protect block-codes and quotes
tyto.protect_bcodes_quotes('wip', post_bottom, article_bottom)
post_bottom = tyto.protect_article.rsplit('\n')
article_bottom = tyto.protect_article
if db.stat_bcodes or db.stat_quotes > 0:
tyto.protect_bcodes_quotes('wip', post_bottom)
post_bottom = tyto.protect_article
# Protect inline-codes
tyto.protect_icodes(post_bottom, article_bottom)
post_bottom = tyto.protect_article.rsplit('\n')
article_bottom = tyto.protect_article
if db.stat_icodes > 0:
tyto.protect_icodes(post_bottom)
post_bottom = tyto.protect_article
# Convert contents from modules
wip_single_tags() # br /, anchors
@ -139,7 +142,7 @@ def wip_article(target):
tyto.replace_in_db(db.post_db, 'wip', db.hash_post)
# Get article DB in html.py
html.set_page(db.uri_file, article_bottom)
html.set_page(db.uri_file, post_bottom)
#print(html.main_page)
# Create wip file
@ -156,40 +159,44 @@ def wip_article(target):
# post is string splitted '\n' #
# article is string not splitted #
#---------------------------------#
def file_to_string(target):
def file_to_string(post_file):
global article
global article_header, article_bottom
global post_header, post_bottom
article = open(target, 'r').read()
post_header = post_bottom = ''
sep = False
article = open(post_file, 'r').read()
# Set from separator, NOT splitted by new line
article_header = article.rsplit('-----')[0]
article_bottom = article.rsplit('-----')[1]
for line in article.rsplit('\n'):
if line.startswith('-----'):
sep = True
continue
# Set from separator, splitted by new line
post_header = article.rsplit('-----')[0].rsplit('\n')
post_bottom = article.rsplit('-----')[1].rsplit('\n')
if sep:
if not post_bottom: post_bottom = line
else: post_bottom = '%s\n%s'%(post_bottom, line)
else:
if not post_header: post_header = line
else: post_header = '%s\n%s'%(post_header, line)
#=============================#
# Convert tags (br /, anchor) #
#-----------------------------#
def wip_single_tags():
global article_bottom
global post_bottom
# <br /> from "|"
article_bottom = article_bottom.replace(
tyto.single_tags[0][0], tyto.single_tags[0][1]
)
post_bottom = post_bottom.replace(tyto.single_tags[0][0],
tyto.single_tags[0][1]
)
for line in article_bottom.rsplit('\n'):
for line in post_bottom.rsplit('\n'):
if line.startswith(tyto.single_tags[1][0]):
set_css = tyto.get_css(line)
article_bottom = article_bottom.replace(
line,
tyto.single_tags[1][1]%set_css
)
post_bottom = post_bottom.replace(line,
tyto.single_tags[1][1]%set_css
)
#==================================#
@ -197,7 +204,7 @@ def wip_single_tags():
# Convert Paragraphs #
#----------------------------------#
def wip_words_tags():
global article_bottom
global post_bottom
# Strongs, italics...
# (Stop after 8 tags)
@ -207,39 +214,39 @@ def wip_words_tags():
if m == 0:
m += 1
# Close anchor (generic)
article_bottom = article_bottom.replace(tag[1], tag[3])
post_bottom = post_bottom.replace(tag[1], tag[3])
continue
elif m > 8: break
# Open tag
article_bottom = article_bottom.replace(tag[0], tag[2])
post_bottom = post_bottom.replace(tag[0], tag[2])
# Close tag
article_bottom = article_bottom.replace(tag[1], tag[3])
post_bottom = post_bottom.replace(tag[1], tag[3])
m += 1
for ln, line in enumerate(article_bottom.rsplit('\n')):
for ln, line in enumerate(post_bottom.rsplit('\n')):
# Paragraphs
# Open tag
if line.startswith(tyto.words_tags[10][0]):
set_css = tyto.get_css(line)
article_bottom = article_bottom.replace(
article_bottom.rsplit('\n')[ln],
tyto.words_tags[10][2]%set_css
)
# Close tag
elif line.startswith(tyto.words_tags[10][1]):
article_bottom = article_bottom.replace(
line,
tyto.words_tags[10][3]
)
if db.stat_paragraphs > 0:
if line.startswith(tyto.words_tags[10][0]):
set_css = tyto.get_css(line)
post_bottom = post_bottom.replace(post_bottom.rsplit('\n')[ln],
tyto.words_tags[10][2]%set_css
)
# Close tag
elif line.startswith(tyto.words_tags[10][1]):
post_bottom = post_bottom.replace(line,
tyto.words_tags[10][3]
)
# Open anchors
if db.stat_anchors == 0: continue
anchor_links = re.findall(r'>_(.+?):', line)
for item in anchor_links:
anchor_id = '%s%s:'%(tyto.words_tags[0][0], item)
article_bottom = article_bottom.replace(
anchor_id, tyto.words_tags[0][2]%item
)
anchor_id = '%s%s:'%(tyto.words_tags[0][0], item)
post_bottom = post_bottom.replace(anchor_id,
tyto.words_tags[0][2]%item
)
#=======================#
@ -248,28 +255,28 @@ def wip_words_tags():
# - file_%i #
#-----------------------#
def wip_links():
global article_bottom
global post_bottom
# Doing files, first, becase of similar marker
if db.uniq_files > 0:
for i in range(1, db.uniq_files + 1):
file = 'db.file_%s'%i
article_bottom = article_bottom.replace(
eval(file)[0]+'+', eval(file)[1]%('_blank')
)
article_bottom = article_bottom.replace(
eval(file)[0], eval(file)[1]%('_self')
)
post_bottom = post_bottom.replace(eval(file)[0]+'+',
eval(file)[1]%('_blank')
)
post_bottom = post_bottom.replace(eval(file)[0],
eval(file)[1]%('_self')
)
if db.uniq_links > 0:
for i in range(1, db.uniq_links + 1):
link = 'link_%s'%i
article_bottom = article_bottom.replace(
eval(link)[0]+'+', eval(link)[1]%('_blank')
)
article_bottom = article_bottom.replace(
eval(link)[0], eval(link)[1]%('_self')
)
post_bottom = post_bottom.replace(eval(link)[0]+'+',
eval(link)[1]%('_blank')
)
post_bottom = post_bottom.replace(eval(link)[0],
eval(link)[1]%('_self')
)
#===============#
@ -278,14 +285,13 @@ def wip_links():
def wip_abbrs():
if db.uniq_abbrs == 0: return
global article_bottom
global post_bottom
for i in range(1, db.uniq_abbrs + 1):
abbr = 'abbr_%s'%i
article_bottom = article_bottom.replace(
eval(abbr)[0],
eval(abbr)[1]
)
post_bottom = post_bottom.replace(eval(abbr)[0],
eval(abbr)[1]
)
#---------------------------------------#
@ -304,12 +310,12 @@ def get_wh_image(value):
def wip_images():
if db.uniq_images == 0: return
global article_bottom
global post_bottom
image_link = '<a class="%s" href="%s" title="%s">%s</a>'
image_show = '<img class="%s" src="%s" alt="%s"%s />'
# Check each line
for ln, line in enumerate(article_bottom.rsplit('\n')):
for ln, line in enumerate(post_bottom.rsplit('\n')):
# match line
if line.startswith('_image:'):
values = line.rsplit(' ')
@ -368,9 +374,9 @@ def wip_images():
# Set HTML to replace line number
image_html = image_tgt%image_src
article_bottom = article_bottom.replace(
article_bottom.rsplit('\n')[ln], image_html
)
post_bottom = post_bottom.replace(post_bottom.rsplit('\n')[ln],
image_html
)
#--------------------------------------------#
@ -388,10 +394,10 @@ def quote_params(qline):
def wip_quotes() :
if db.stat_quotes == 0: return
global article_bottom
global post_bottom
global author, link, lang, book, date
for ln, line in enumerate(article_bottom.rsplit('\n')):
for ln, line in enumerate(post_bottom.rsplit('\n')):
# Decode from base64
if line.startswith('Q64'):
line = line.replace('Q64.', '')
@ -424,9 +430,9 @@ def wip_quotes() :
else: tab_c = tab_c + 2
# Replace opened paragrph with html line
qline_html = '%s%s'%(
tab_p * ' ', tyto.words_tags[10][2]%par_css
)
qline_html = '%s%s'%(tab_p * ' ',
tyto.words_tags[10][2]%par_css
)
# Add line to quote_html
if quote_html:
@ -518,9 +524,9 @@ def wip_quotes() :
'</blockquote>'
# Replace line with final HTML Quote
article_bottom = article_bottom.replace(
'Q64.%s.Q64'%line, quote_html
)
post_bottom = post_bottom.replace('Q64.%s.Q64'%line,
quote_html
)
#==========================#
@ -530,13 +536,13 @@ def wip_quotes() :
def wip_icodes():
if db.stat_icodes == 0: return
global article_bottom
global post_bottom
matches = re.findall(r'I64.(.*?).I64', article_bottom)
matches = re.findall(r'I64.(.*?).I64', post_bottom)
for match in matches:
rep_icode = 'I64.' + match + '.I64'
src_icode = tyto.b64("Decode", match, 'I64.', '.I64')
article_bottom = article_bottom.replace(rep_icode, src_icode)
post_bottom = post_bottom.replace(rep_icode, src_icode)
#==================================================#
@ -546,9 +552,9 @@ def wip_icodes():
def wip_bcodes():
if db.stat_bcodes == 0: return
global article_bottom
global post_bottom
matches = re.findall(r'B64.(.*?).B64', article_bottom)
matches = re.findall(r'B64.(.*?).B64', post_bottom)
for match in matches:
rep_bcode = 'B64.' + match + '.B64'
src_bcode = tyto.b64("Decode", match, 'B64.', '.B64')
@ -566,9 +572,11 @@ def wip_bcodes():
'</pre>'
# Block-code content per line
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
)
article_bottom = article_bottom.replace(rep_bcode, html_bcode)
post_bottom = post_bottom.replace(rep_bcode, html_bcode)
#========================================#
@ -578,11 +586,11 @@ def wip_bcodes():
def wip_titles():
if db.stat_titles == 0: return
global article_bottom
article_temp = article_bottom
global post_bottom
article_temp = post_bottom
article_tmp2 = '' # Construct article, without empty lines
for line in article_bottom.rsplit('\n'):
for line in post_bottom.rsplit('\n'):
if line.startswith('#'):
hx = line[1]
title_cont = line[2: len(line)].lstrip()
@ -635,7 +643,7 @@ def wip_titles():
article_temp = '%s\n</div>'%article_temp
# Replace article with new contents
article_bottom = article_temp
post_bottom = article_temp
#==============================================#
@ -671,7 +679,7 @@ def wip_raws(target):
# Make HTML tabulations #
#-----------------------#
def wip_tabs():
global article_bottom
global post_bottom
article_temp = ''
tab = tab_start = 6 # From <article> tag
indiv = False
@ -685,7 +693,7 @@ def wip_tabs():
'6' : '16'
}
for line in article_bottom.rsplit('\n'):
for line in post_bottom.rsplit('\n'):
# Titles
if line.startswith('<h'):
get_tab = line[2]
@ -712,5 +720,5 @@ def wip_tabs():
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
post_bottom = article_temp