New cleaned code. Indev for wip. Some convertions done
This commit is contained in:
parent
9cbe55df24
commit
4491cb94d2
|
@ -63,7 +63,7 @@ def manage_check(target, option):
|
|||
article_bottom = tyto.protect_article
|
||||
|
||||
# Protect block-codes and quotes
|
||||
tyto.protect_bcodes_quotes('check', post_bottom)
|
||||
tyto.protect_bcodes_quotes('check', post_bottom, article_bottom)
|
||||
post_bottom = tyto.protect_article.rsplit('\n')
|
||||
article_bottom = tyto.protect_article
|
||||
|
||||
|
@ -99,13 +99,13 @@ def isin(term, post_bottom):
|
|||
# Check if separator or exit #
|
||||
#---------------------------------#
|
||||
def file_to_string(post_file):
|
||||
# Check if separator
|
||||
global article
|
||||
global article_header, article_bottom
|
||||
global post_header, post_bottom
|
||||
|
||||
article = open(post_file, 'r').read()
|
||||
|
||||
# Check if separator or exit
|
||||
if not '-----' in article:
|
||||
tyto.exiting("6", '-----', True)
|
||||
|
||||
|
@ -528,8 +528,11 @@ def check_content(post_bottom):
|
|||
# Create new article's database at each check ! #
|
||||
#-----------------------------------------------#
|
||||
def create_database():
|
||||
# No first / from dir post
|
||||
web_uri = tyto.web_uri[1: len(tyto.web_uri)]
|
||||
# No need index.html for web link
|
||||
if tyto.web_uri.endswith('index.html'): tyto.web_uri = '/'
|
||||
|
||||
database = '# Post Configuration for Tyto\n' + \
|
||||
'post_id = "%s"\n'%tyto.uri_id + \
|
||||
'root_uri = "%s"\n'%tyto.uri_root + \
|
||||
|
|
|
@ -128,7 +128,6 @@ words_tags = [
|
|||
('-(', '-)', '-(', '-)', 'lists', 't')
|
||||
]
|
||||
|
||||
|
||||
# Tags that do not need to be paired
|
||||
#-----------------------------------
|
||||
single_tags = [
|
||||
|
@ -312,11 +311,12 @@ def protect_icodes(post_bottom, article_bottom):
|
|||
# For check, create new article without bcode #
|
||||
# For wip, remplace content with base64 #
|
||||
#---------------------------------------------#
|
||||
def protect_bcodes_quotes(process, post_bottom):
|
||||
def protect_bcodes_quotes(process, post_bottom, article_bottom):
|
||||
|
||||
global protect_article
|
||||
in_bcode = in_quote = False
|
||||
protect_article = ''
|
||||
temp_article = article_bottom
|
||||
|
||||
if process == 'check':
|
||||
global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB
|
||||
|
@ -350,6 +350,53 @@ def protect_bcodes_quotes(process, post_bottom):
|
|||
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':
|
||||
|
||||
# Convert bcodes and quotes
|
||||
# include markers in base64, remove from article
|
||||
bcode = quote = ''
|
||||
for ln, line in enumerate(post_bottom):
|
||||
# bcode
|
||||
if line.startswith(words_tags[12][0]):
|
||||
in_bcode = True
|
||||
elif line.startswith(words_tags[12][1]):
|
||||
bcode = '%s\n%s'%(bcode, line)
|
||||
in_bcode = False
|
||||
b64_bcode = b64('Encode', bcode)
|
||||
protect_article = '%s\n%s'%(protect_article, b64_bcode)
|
||||
bcode = ''
|
||||
continue
|
||||
elif line.startswith('#'): # As convention
|
||||
if not line.startswith(titles_tags):
|
||||
continue
|
||||
|
||||
# quote
|
||||
elif line.startswith(words_tags[11][0]):
|
||||
if not in_bcode:
|
||||
in_quote = True
|
||||
elif line.startswith(words_tags[11][1]):
|
||||
if not in_bcode:
|
||||
quote = '%s\n%s'%(quote, line)
|
||||
in_quote = False
|
||||
b64_quote = b64('Encode', quote)
|
||||
protect_article = '%s\n%s'%(protect_article, b64_quote)
|
||||
quote = ''
|
||||
continue
|
||||
|
||||
# Priority to bcode
|
||||
if in_bcode:
|
||||
if bcode: bcode = '%s\n%s'%(bcode, line)
|
||||
else: bcode = line
|
||||
else:
|
||||
if in_quote:
|
||||
if quote: quote = '%s\n%s'%(quote, line)
|
||||
else: quote = line
|
||||
else:
|
||||
if not protect_article: protect_article = line
|
||||
else: protect_article = '%s\n%s'%(protect_article, line)
|
||||
|
||||
|
||||
#=====================================#
|
||||
# Encode/Decode string to/from base64 #
|
||||
|
|
|
@ -25,6 +25,7 @@ def manage_wip(target, option):
|
|||
|
||||
# Article exists + has DB ?
|
||||
db_exists = tyto.get_db_post(target)
|
||||
target = tyto.uri_root
|
||||
if not db_exists:
|
||||
tyto.exiting("4", '', True)
|
||||
|
||||
|
@ -39,7 +40,7 @@ def manage_wip(target, option):
|
|||
|
||||
# In any case, if Force
|
||||
if option == 'Force':
|
||||
wip_article()
|
||||
wip_article(target)
|
||||
return
|
||||
|
||||
# Compare and check file
|
||||
|
@ -52,7 +53,7 @@ def manage_wip(target, option):
|
|||
if hash_wip:
|
||||
if not is_file: tyto.exiting("1", wip_uri, False)
|
||||
if is_new: tyto.exiting("9", '', False)
|
||||
wip_article()
|
||||
wip_article(target)
|
||||
else:
|
||||
tyto.exiting("20", date_wip, True)
|
||||
|
||||
|
@ -61,9 +62,127 @@ def manage_wip(target, option):
|
|||
# Start wip modules #
|
||||
# Set Db #
|
||||
#-------------------#
|
||||
def wip_article():
|
||||
def wip_article(target):
|
||||
print('Convert')
|
||||
|
||||
# Convert anchors
|
||||
#tyto.get_css(line)
|
||||
#print(tyto.single_tags[1][1]%tyto.set_css)
|
||||
# Convert file to strings
|
||||
file_to_string(target)
|
||||
|
||||
global post_header, article_header
|
||||
global post_bottom, article_bottom
|
||||
|
||||
# Protect inline-codes
|
||||
tyto.protect_icodes(post_bottom, article_bottom)
|
||||
post_bottom = tyto.protect_article.rsplit('\n')
|
||||
article_bottom = tyto.protect_article
|
||||
|
||||
# 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
|
||||
|
||||
# Convert contents from modules
|
||||
wip_single_tags() # br /, anchors
|
||||
wip_words_tags() # Paragraphs, strongs, italics
|
||||
wip_links() # Links from headers in DB
|
||||
|
||||
print(article_bottom)
|
||||
|
||||
#=================================#
|
||||
# Create string article from file #
|
||||
# post is string splitted '\n' #
|
||||
# article is string not splitted #
|
||||
#---------------------------------#
|
||||
def file_to_string(target):
|
||||
global article
|
||||
global article_header, article_bottom
|
||||
global post_header, post_bottom
|
||||
|
||||
article = open(target, 'r').read()
|
||||
|
||||
# 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')
|
||||
|
||||
|
||||
#=============================#
|
||||
# Convert tags (br /, anchor) #
|
||||
#-----------------------------#
|
||||
def wip_single_tags():
|
||||
global article_bottom
|
||||
|
||||
# <br /> from "|"
|
||||
article_bottom = article_bottom.replace(
|
||||
tyto.single_tags[0][0], tyto.single_tags[0][1]
|
||||
)
|
||||
|
||||
for line in article_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
|
||||
)
|
||||
|
||||
|
||||
#==================================#
|
||||
# Convert tags (strong, icodes...) #
|
||||
# Convert Paragraphs #
|
||||
#----------------------------------#
|
||||
def wip_words_tags():
|
||||
global article_bottom
|
||||
|
||||
# Strongs, italics... (8 tags)
|
||||
m = 0
|
||||
for tag in tyto.words_tags:
|
||||
if m > 8: break
|
||||
|
||||
# Open tag
|
||||
article_bottom = article_bottom.replace(tag[0], tag[2])
|
||||
# Close tag
|
||||
article_bottom = article_bottom.replace(tag[1], tag[3])
|
||||
m += 1
|
||||
|
||||
# Paragraphs
|
||||
for ln, line in enumerate(article_bottom.rsplit('\n')):
|
||||
# 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
|
||||
if line.startswith(tyto.words_tags[10][1]):
|
||||
article_bottom = article_bottom.replace(
|
||||
line,
|
||||
tyto.words_tags[10][3]
|
||||
)
|
||||
|
||||
|
||||
#=======================#
|
||||
# Convert links from DB #
|
||||
# - link_%i #
|
||||
# - file_%i #
|
||||
#-----------------------#
|
||||
def wip_links():
|
||||
global article_bottom
|
||||
|
||||
if uniq_links > 0:
|
||||
for i in range(1, uniq_links + 1):
|
||||
link = 'link_%s'%i
|
||||
article_bottom = article_bottom.replace(
|
||||
eval(link)[0], eval(link)[1]
|
||||
)
|
||||
|
||||
if uniq_files > 0:
|
||||
for i in range(1, uniq_files + 1):
|
||||
file = 'file_%s'%i
|
||||
article_bottom = article_bottom.replace(
|
||||
eval(file)[0], eval(file)[1]
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue