[1.9.25] - new anchors process (HTML prepared at 'check')

This commit is contained in:
Cyrille L 2023-10-15 01:59:45 +02:00
parent 6d5a75b4bf
commit 359595d643
14 changed files with 95 additions and 17 deletions

View File

@ -9,6 +9,10 @@ Tyto - Littérateur
# CURRENTLY IN DEV ! # CURRENTLY IN DEV !
## [1.9.25]
- fix typo when creating HTML list
- new anchors process (HTML prepared at 'check')
## [1.9.24] ## [1.9.24]
- new list process (HTML prepared at 'check') - new list process (HTML prepared at 'check')

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.24 # Version: 1.9.25
# Updated: 2023-10-14 1697296197 # Updated: 2023-10-15 1697327876
# Tyto - Littérateur # Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org> # Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -137,6 +137,10 @@ def valid(target):
post.error == 0 and sl_stags() \ post.error == 0 and sl_stags() \
or tools.exit(targets, post.error) or tools.exit(targets, post.error)
# Anchors links
post.error == 0 and anchors_links() \
or tools.exit(targets, post.error)
# Quotes # Quotes
post.error == 0 and sl_ptags(post.ptags[1]) \ post.error == 0 and sl_ptags(post.ptags[1]) \
or tools.exit(targets, post.error) or tools.exit(targets, post.error)
@ -480,14 +484,6 @@ def is_value2_file_exists(ln, tag, val2):
#=====================# #=====================#
# check text contents #======================================================== # check text contents #========================================================
#=====================# #=====================#
#=======================================#
# bcodes: first process ! #
#---------------------------------------#
#=========================================# #=========================================#
# start line paired tags # # start line paired tags #
# Generic check for all paired markers # # Generic check for all paired markers #
@ -697,6 +693,9 @@ def icodes():
# Return True/False # # Return True/False #
#----------------------------# #----------------------------#
def sl_stags(): def sl_stags():
global anchors_ids
anchors_ids = () # Uniq anchors IDs
for ln, line in enumerate(texts, post.head_lines + 1): for ln, line in enumerate(texts, post.head_lines + 1):
# legacy Tyto Titles # legacy Tyto Titles
if line.startswith(post.tyto_titles): if line.startswith(post.tyto_titles):
@ -705,7 +704,7 @@ def sl_stags():
debug.out(52, "%s. %s ?"%(ln, line), post.uri, True, 2, False) debug.out(52, "%s. %s ?"%(ln, line), post.uri, True, 2, False)
return False return False
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...) # Avoid wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
elif line[1].isdigit() and int(line[1]) >= 6: elif line[1].isdigit() and int(line[1]) >= 6:
post.error = \ post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False) debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
@ -723,10 +722,12 @@ def sl_stags():
html_val = post.html_titles[mark]%(css, title) html_val = post.html_titles[mark]%(css, title)
post.cf_set("TITLES", html_var, html_val) post.cf_set("TITLES", html_var, html_val)
# Count Tyto Comments # Count Tyto Comments
elif line.lstrip().startswith("#"): elif line.lstrip().startswith("#"):
post.stats_tyto_text_coms += 1 post.stats_tyto_text_coms += 1
# Count HTML comments # Count HTML comments
elif line.lstrip().startswith(post.text_comments): elif line.lstrip().startswith(post.text_comments):
post.stats_html_coms += 1 post.stats_html_coms += 1
@ -752,9 +753,66 @@ def sl_stags():
post.cf_set("IMAGES", link_var, link_val) post.cf_set("IMAGES", link_var, link_val)
post.cf_set("IMAGES", html_var, html_val) post.cf_set("IMAGES", html_var, html_val)
# Anchor source
elif line.lstrip().startswith(post.anchor_target[0]):
anchor_id = tools.get_css(line, post.anchor_target[0])
if anchor_id in anchors_ids:
post_error = \
debug.out(54, '%s) "%s"'%(ln, anchor_id), post.uri, True, 2, False)
return False
anchors_ids = (*anchors_ids, anchor_id)
post.stats_text_anc_ids += 1
return True return True
#===========================#
# Find and anchors links #
# Check if anchor_id exists #
#---------------------------#
def anchors_links():
markers = post.anchor_link
for ln, line in enumerate(texts, post.head_lines + 1):
anc_links = re.findall('%s(.*?)%s'%(markers[0], markers[1]), line)
if not anc_links:
continue
for anc_link in anc_links:
if not ":" in anc_link:
debug.out(51, '%s) ">_id:%s_<"'%(
ln, langs.logs.anchor_title,
), post.uri, True, 1, False)
continue
anc_id = anc_link.rsplit(":")[0]
if anc_id in anchors_ids:
anc_title = anc_link.rsplit(":")[1].lstrip()
if not anc_title:
post.error = \
debug.out(51, '%s) ">_%s:?_<"'%(
ln, anc_id
), post.uri, True, 2, False)
return False
# Set to post Database
post.stats_text_anc_links += 1
post.cf_set("ANCHORS",
"anchor_%s"%post.stats_text_anc_links,
post.anchor_set[0]%anc_link
)
post.cf_set("ANCHORS",
"html_%s"%post.stats_text_anc_links,
post.anchor_set[1]%(css, anc_id, anc_title)
)
else:
post.error = \
debug.out(51, '%s) "-> %s"'%(ln, anc_id), post.uri, True, 2, False)
return False
return True
#================================# #================================#
# Update post configuration file # # Update post configuration file #
#--------------------------------# #--------------------------------#
@ -822,6 +880,8 @@ def cf_update_values():
post.cf_set("STATS_TEXTS", "lines", str(post.text_lines)) post.cf_set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf_set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms)) post.cf_set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
post.cf_set("STATS_TEXTS", "html_coms", str(post.stats_html_coms)) post.cf_set("STATS_TEXTS", "html_coms", str(post.stats_html_coms))
post.cf_set("STATS_TEXTS", "anc_targets", str(post.stats_text_anc_ids))
post.cf_set("STATS_TEXTS", "anc_links", str(post.stats_text_anc_links))
post.cf_set("STATS_TEXTS", "titles", str(post.stats_titles)) post.cf_set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf_set("STATS_TEXTS", "bcodes", str(post.ptags_stats["bcodes"])) post.cf_set("STATS_TEXTS", "bcodes", str(post.ptags_stats["bcodes"]))
post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines)) post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))

View File

@ -92,7 +92,7 @@ def out(nbr, var, val, show, color, stop):
51 : langs.logs.err_post_data, 51 : langs.logs.err_post_data,
52 : langs.logs.err_post_title, 52 : langs.logs.err_post_title,
53 : langs.logs.err_post_paired, 53 : langs.logs.err_post_paired,
54 : langs.logs.err_post_indent, 54 : langs.logs.err_post_id_yet,
55 : langs.logs.err_post_in_tag, 55 : langs.logs.err_post_in_tag,
56 : langs.logs.err_post_datatag, 56 : langs.logs.err_post_datatag,
# WARNINGS (100-200) # WARNINGS (100-200)

View File

@ -262,6 +262,8 @@ stats_abbrs = 0
stats_total_files = 0 stats_total_files = 0
stats_text_anc_ids = 0
stats_text_anc_links = 0
stats_text_links = 0 stats_text_links = 0
stats_text_files = 0 stats_text_files = 0
stats_text_images = 0 stats_text_images = 0
@ -340,6 +342,9 @@ html_titles = {
html_brline = ("|", '<br class="%s%s">') html_brline = ("|", '<br class="%s%s">')
html_hrline = ("--", '<hr class="%s%s">') html_hrline = ("--", '<hr class="%s%s">')
text_comments = (";;", "<!--") text_comments = (";;", "<!--")
anchor_target = ("->", '<a id="%s" class="anchor_target"></a>')
anchor_link = (">_", "_<")
anchor_set = (">_%s_<", '<a class="%s anchor_link" href="#%s">%s</a>')
quote_metas = ("cite:", "date:", "book:", "lang:", "link:") quote_metas = ("cite:", "date:", "book:", "lang:", "link:")
@ -370,6 +375,8 @@ ini_template = """[DOMAIN]
[TITLES] [TITLES]
[ANCHORS]
[LINKS] [LINKS]
[FILES] [FILES]

View File

@ -201,12 +201,16 @@ def convert_html_signs(string):
#==========================# #==========================#
# Get CSS value after mark # # Get CSS value after mark #
# Only take the first name # # Only take the first name #
# Exit all process if _... #
#--------------------------# #--------------------------#
def get_css(line, mark): def get_css(line, mark):
css = line.rsplit(mark)[1].lstrip().rsplit(" ")[0] css = line.rsplit(mark)[1].lstrip().rsplit(" ")[0]
if not css: css = css or domain.css
css = domain.css
# Tyto use _abc as markers
if css.startswith("_"):
debug.out(56, "'_...' (CSS: %s)"%css, post.uri, True, 2, True)
return css return css

View File

@ -194,7 +194,7 @@ def list(lines):
# Final HTML list with css class # Final HTML list with css class
list_html = convert_list(list_raw, post.ptags[3][3], post.ptags[3][4]) list_html = convert_list(list_raw, post.ptags[3][3], post.ptags[3][4])
list_html = list_html.replace(">", ' class="%s">'%css, 1) list_html = list_html.replace(">", ' class="%s">'%css, 1)
list_html = list_html.replace("<li>", ' <li class="%s>"'%css) list_html = list_html.replace("<li>", ' <li class="%s">'%css)
return list_html return list_html

View File

@ -44,6 +44,9 @@ domain_tags = "Mots-clés génériques [1,2,3]"
domain_lang = "Langue du site web" domain_lang = "Langue du site web"
domain_srv = "URI du serveur" domain_srv = "URI du serveur"
# Misc
anchor_title = "Titre de l'ancre"
# logs for debug # logs for debug
#--------------- #---------------
# Errors # Errors
@ -66,7 +69,7 @@ err_post_title = "Titre invalide"
err_post_paired = "Marqueurs non apairés" err_post_paired = "Marqueurs non apairés"
err_post_in_tag = "Marqueurs sans contenu" err_post_in_tag = "Marqueurs sans contenu"
err_post_datatag= "Donnée réservée" err_post_datatag= "Donnée réservée"
err_post_indent = "Ligne non indentée" err_post_id_yet = "Identité déjà utilisée"
# Warnings # Warnings
warn_no_dom = "Domaine non configuré" warn_no_dom = "Domaine non configuré"