[1.9.24] - new list process (HTML prepared at 'check')

This commit is contained in:
Cyrille L 2023-10-14 17:13:12 +02:00
parent 8843fd3f76
commit 6d5a75b4bf
31 changed files with 169 additions and 30 deletions

View File

@ -9,6 +9,9 @@ Tyto - Littérateur
# CURRENTLY IN DEV ! # CURRENTLY IN DEV !
## [1.9.24]
- new list process (HTML prepared at 'check')
## [1.9.23] ## [1.9.23]
- new quote process (HTML prepared at 'check') - new quote process (HTML prepared at 'check')

View File

@ -8,11 +8,11 @@ tyto
``` ```
## ToDo next (working on) ## ToDo next (working on)
- added lists to post database (prepared wip)
## Working on
- 'check' action processes - 'check' action processes
- - wip quotes - thinking about creating an auto top article menu from titles
- - support for words tags (bolds...) - stats for article words
- - support lists, anchors
- - thinking about creating an auto top article menu from titles
- - stats for article words
- Translate logs in english ! - Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.23 # Version: 1.9.24
# Updated: 2023-10-14 1697274575 # Updated: 2023-10-14 1697296197
# 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>
@ -19,7 +19,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Main binary to execute. # Description: Main binary to execute.
# Import modules and start checking/using arguments # Import modules and start checking/using arguments

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Manage arguments from command line # Description: Manage arguments from command line
# File: /var/lib/tyto/program/args.py # File: /var/lib/tyto/program/args.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Mainly to check article, but also domain and more # Description: Mainly to check article, but also domain and more
# File: /var/lib/tyto/program/check.py # File: /var/lib/tyto/program/check.py
@ -115,25 +115,35 @@ def valid(target):
# Text article # Text article
# ============ # ============
# Process bcodes and icodes first to protect their contents # Process bcodes and icodes first to protect their contents
post.error == 0 and sl_ptags(post.ptags[0]) or tools.exit(targets, post.error) post.error == 0 and sl_ptags(post.ptags[0]) \
post.error == 0 and icodes() or tools.exit(targets, post.error) or tools.exit(targets, post.error)
post.error == 0 and icodes() \
or tools.exit(targets, post.error)
# ============= # =============
# Head contents # Head contents
# ============= # =============
# One Line targs in head_contents # One Line targs in head_contents
post.error == 0 and ol_tags() or tools.exit(targets, post.error) post.error == 0 and ol_tags() \
or tools.exit(targets, post.error)
# Multiple and optional Tags on 3 linges # Multiple and optional Tags on 3 linges
post.error == 0 and ml_tags() or tools.exit(targets, post.error) post.error == 0 and ml_tags() \
or tools.exit(targets, post.error)
# ============ # ============
# Text article # Text article
# ============ # ============
# Single tags # Single tags
post.error == 0 and sl_stags() or tools.exit(targets, post.error) post.error == 0 and sl_stags() \
or tools.exit(targets, post.error)
# Quotes # Quotes
post.error == 0 and sl_ptags(post.ptags[1]) or tools.exit(targets, post.error) post.error == 0 and sl_ptags(post.ptags[1]) \
or tools.exit(targets, post.error)
# Lists
post.error == 0 and sl_ptags(post.ptags[3]) \
or tools.exit(targets, post.error)
return True return True
@ -496,6 +506,7 @@ def sl_ptags(markers):
convert = { convert = {
"bcodes" : wip.bcode, "bcodes" : wip.bcode,
"quotes" : wip.quote, "quotes" : wip.quote,
"lists" : wip.list,
} }
index0 = index1 = -1 index0 = index1 = -1
@ -815,6 +826,7 @@ def cf_update_values():
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))
post.cf_set("STATS_TEXTS", "quotes", str(post.ptags_stats["quotes"])) post.cf_set("STATS_TEXTS", "quotes", str(post.ptags_stats["quotes"]))
post.cf_set("STATS_TEXTS", "lists", str(post.ptags_stats["lists"]))
# Founds from header tags # Founds from header tags
post.cf_set("STATS_TEXTS", "links", str(post.stats_text_links)) post.cf_set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf_set("STATS_TEXTS", "files", str(post.stats_text_files)) post.cf_set("STATS_TEXTS", "files", str(post.stats_text_files))

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Add more logs when debug is set in command line # Description: Add more logs when debug is set in command line
# File: /var/lib/tyto/program/debug.py # File: /var/lib/tyto/program/debug.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Manage configuration domain(s) # Description: Manage configuration domain(s)
# File: /var/lib/tyto/program/domain.py # File: /var/lib/tyto/program/domain.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Forms (edit, create domain, questions...) # Description: Forms (edit, create domain, questions...)
# File: /var/lib/tyto/program/form.py # File: /var/lib/tyto/program/form.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Show help commands # Description: Show help commands
# File: /var/lib/tyto/program/help.py # File: /var/lib/tyto/program/help.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Load lang logs file according to system language # Description: Load lang logs file according to system language
# Load lang site file according to domain configuration # Load lang site file according to domain configuration

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: When user wants to create something new # Description: When user wants to create something new
# File: /var/lib/tyto/program/new.py # File: /var/lib/tyto/program/new.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: About post (from target) database, uri... # Description: About post (from target) database, uri...
# File: /var/lib/tyto/program/new.py # File: /var/lib/tyto/program/new.py
@ -317,7 +317,7 @@ ptags = (
("{{", "}}", "bcodes"), ("{{", "}}", "bcodes"),
("[[", "]]", "quotes"), ("[[", "]]", "quotes"),
("((", "))", "parags", '<p class="%s">', "</p>"), ("((", "))", "parags", '<p class="%s">', "</p>"),
("<<", ">>", "lists" ), ("<<", ">>", "lists", "=", "+"),
) )
ptags_stats = { ptags_stats = {
@ -380,6 +380,8 @@ ini_template = """[DOMAIN]
[QUOTES] [QUOTES]
[LISTS]
[RAWS] [RAWS]
[CODES] [CODES]

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: When user wants to see something # Description: When user wants to see something
# File: /var/lib/tyto/program/show.py # File: /var/lib/tyto/program/show.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Tools used by Tyto - Littérateur # Description: Tools used by Tyto - Littérateur
# File: /var/lib/tyto/program/tools.py # File: /var/lib/tyto/program/tools.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: Templates, settings, values # Description: Templates, settings, values
# File: /var/lib/tyto/program/tyto.py # File: /var/lib/tyto/program/tyto.py

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# #
# Description: When user wants to set something (mainly in domain) # Description: When user wants to set something (mainly in domain)
# File: /var/lib/tyto/program/set.py # File: /var/lib/tyto/program/set.py

View File

@ -2,6 +2,7 @@
# 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>
# Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -17,9 +18,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re) # XMPP: echolib > im@echolib.re
# XMPP: neox > neox@a-lec.org
# #
# Description: Convert texts to HTML # Description: Convert texts to HTML
# Create HTML page with 'wip' command
# File: /var/lib/tyto/program/wip.py # File: /var/lib/tyto/program/wip.py
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -34,6 +37,7 @@
import tyto, tools, post, domain import tyto, tools, post, domain
#=========================================================# #=========================================================#
# Prepared HTML datas in post Database at 'check' process #==================== # Prepared HTML datas in post Database at 'check' process #====================
# Return new string to be converted to one line base64 # # Return new string to be converted to one line base64 #
@ -158,11 +162,129 @@ def quote(lines):
footer footer
) )
print(html_quote) #print(html_quote)
return html_quote return html_quote
#===================#
# Create HTML list #
# convert raw lines #
#-------------------#
def list(lines):
lines = lines.rsplit("\n")
list_raw = ""
for ln, line in enumerate(lines):
line = line.lstrip()
# Open Marker (Unused in HTML). Get user CSS class
if ln == 0:
css = tools.get_css(line, post.ptags[3][0])
continue
# Closed marker (Unused in HTML)
elif ln == len(lines) - 1:
continue
if list_raw: list_raw = "%s\n%s"%(list_raw, line)
else: list_raw = line
# Final HTML list with css class
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("<li>", ' <li class="%s>"'%css)
return list_html
#====================================================================#
# Tool to convert content lists to HTML #
# markdown_str: from lists_to_HTML() #
# So many THANX neox ! #
# (Not sure, i was able to do it and even not in a so beautiful way) #
#--------------------------------------------------------------------#
def convert_list(markdown_str, mark_b, mark_c):
# First step : reshape lines
items = []
inside_item = 0
index = -1
# Cut string with \n's
strlist = markdown_str.split("\n")
# Find items
for i in range(len(strlist)):
if strlist[i] == "":
continue
# = and +
if strlist[i][0] != mark_b and \
strlist[i][0] != mark_c:
if inside_item != 1:
inside_item = 1
else:
inside_item = 0
if inside_item == 0:
items.append(strlist[i])
index += 1
if inside_item == 1:
items[index] = '%s '%items[index] # Add one space
items[index] += strlist[i].lstrip()
# Second step : parsing
UL = 1
OL = 2
CLOSING = ["ERROR", "</ul>\n", "</ol>\n"]
OPENING = ["ERROR", "<ul>\n", "<ol>\n"]
rank_stack = []
rank = 0
cur_rank = 0
state = 0
old_state = 0
work_str = ""
for i in range(len(items)):
rank = cur_rank
descriptor = items[i].split(" ")[0]
text = items[i][items[i].find(" "):].lstrip()
cur_rank = len(descriptor)
if "=" in descriptor:
state = UL
elif "+" in descriptor:
state = OL
else:
raise(Exception)
# rank up
if cur_rank > rank:
for i in range(cur_rank - rank):
work_str += " "*(rank+i) + OPENING[state]
rank_stack.append(state)
# rank down
elif cur_rank < rank:
for i in range(rank - cur_rank):
work_str += " "*(rank-i-1) + CLOSING[rank_stack.pop()]
work_str += " "*cur_rank + '<li>' + text + "</li>\n"
for i in range(cur_rank):
work_str += " "*(cur_rank-i-1) + CLOSING[rank_stack.pop()]
return work_str
#=========================#
# WIP process #====================================================
# Convert article to HTML #
# Create new file #
#-------------------------#
#============================# #============================#
# code # # code #
# Used by check module that # # Used by check module that #