diff --git a/CHANGELOG.md b/CHANGELOG.md index 705e5f4..081bb72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,13 @@ Tyto - Littérateur # CURRENTLY IN DEV ! +## [1.9.15] +- Added 'check' process for bcodes, quotes and paragraphs + stats +- - Their contents must be indented +- - replace with empty lines for bcodes and quotes + ## [1.9.14] -- added 'check' process on block-codes +- added 'check' process for block-codes ## [1.9.13] - Check: One-Line needed tags, titles diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 471be4d..07d1607 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.14 -# Updated: 2023-10-01 1696152727 +# Version: 1.9.15 +# Updated: 2023-10-02 1696231003 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc index 40f97f2..66120be 100644 Binary files a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc index 44dee06..9ba86fe 100644 Binary files a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 3f0882b..a76e722 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -73,12 +73,11 @@ def manage(action, target): def is_article(target): valid(target) - print("pass", post.error, args.targets) print("chk_date", chk_date) - - print("Stats coms =", post.stats_tyto_coms, post.stats_html_coms) - print("Titles =", post.stats_titles) - + print() + print("Final text_contents string") + for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines): + print(">", ln, line) #===========================================# # Check full article contents (head + text) # @@ -97,7 +96,9 @@ def valid(target): # Text article # ============ - post.error == 0 and bcodes() or tools.exit(targets, post.error) + post.error == 0 and sl_paired("bcodes") or tools.exit(targets, post.error) + post.error == 0 and sl_paired("quotes") or tools.exit(targets, post.error) + post.error == 0 and sl_paired("parags") or tools.exit(targets, post.error) post.error == 0 and titles() or tools.exit(targets, post.error) @@ -216,70 +217,68 @@ def is_valid_date(date): # Create new post.text_contents # # Return True/False # #---------------------------------------# -def bcodes(): +def sl_paired(markers): new_text_contents = "" - opened = closed = False - closed_bcodes_nbr = 0 # To compare with post.stats_bcodes + opened = closed = in_tag = False + stats_opened = stats_closed = 0 + tags = () - for ln, line in enumerate(post.text_contents.rsplit("\n"), - post.head_lines + 1): + if markers == "bcodes" : tags = post.bcodes + elif markers == "quotes" : tags = post.quotes + elif markers == "parags" : tags = post.parags - # Opened tag - if line.startswith(post.bcodes[0]): + # loop lines in text_contents + for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines): + + # Tag was closed, but not in_tag content line + if closed and in_tag: + in_tag = False + + # Tag is opened + if line.startswith(tags[0]): + # Tag was already opened if opened: post.error = \ debug.out(53, "%s) %s ... %s"%( - ln, - post.bcodes[0], post.bcodes[1] - ), post.uri, True, 2, False) + ln, + tags[0], tags[1] + ), post.uri, True, 2, False) return False - - opened = True - post.stats_bcodes += 1 - continue + opened = in_tag = True + closed = False + stats_opened += 1 - # Close tag - elif line.startswith(post.bcodes[1]): + # Tag is closed + if line.startswith(tags[1]): + # Tag was already closed if closed: post.error = \ debug.out(53, "%s) %s ... %s"%( - ln, - post.bcodes[0], post.bcodes[1] - ), post.uri, True, 2, False) + ln, + tags[0], tags[1] + ), post.uri, True, 2, False) return False - closed = True - closed_bcodes_nbr += 1 - - if not opened: - post.error = \ - debug.out(53, "%s) %s ... %s"%( - ln, - post.bcodes[0], post.bcodes[1] - ), post.uri, True, 2, False) - return False + opened = False + stats_closed += 1 - # Contents must be indented - if opened and not closed: - if len(line) - len(line.lstrip()) < 3: - post.error = \ - debug.out(54, "%s) %s..."%(ln, line[0:10]), post.uri, True, 2, False) - return False - - # Create new string - if not opened and not closed: + + if in_tag: + # Contents must be indented + if not line.startswith(tags): + if len(line) - len(line.lstrip()) < 3: + post.error = \ + debug.out(54, "%s) %s..."%(ln, line[0:10]), post.uri, True, 2, False) + return False + line = "" + + # Create new string, removing in_tag line if in bcodes or quotes + if markers in post.raw_contents: if not new_text_contents: new_text_contents = line - else: new_text_contents = "%s\n%s"%(new_text_contents, line) - - # Check if tags are paired - if post.stats_bcodes != closed_bcodes_nbr: - post.error = \ - debug.out(53, "%s ... %s"%( - post.bcodes[0], post.bcodes[1] - ), post.uri, True, 2, False) - return False + else: new_text_contents = "%s\n%s"%(new_text_contents, line) + + post.text_contents = new_text_contents - post.text_contents = new_text_contents return True diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py index 80a31ab..5d59074 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -116,7 +116,7 @@ def is_tyto_format(): error = debug.out(23, "?", uri, True, 2, False) return False - head_lines = len(head_contents.rsplit("\n")) + head_lines = len(head_contents.rsplit("\n")) +1 # after separator text_lines = lines - head_lines return True @@ -180,6 +180,9 @@ bcodes = ("{{", "}}") quotes = ("[[", "]]") parags = ("((", "))") +# markers with "protected" contents +raw_contents = ("bcodes", "quotes") + # Comments text_comments = (";;", "" } @@ -200,3 +203,5 @@ stats_tyto_coms = 0 stats_html_coms = 0 stats_titles = 0 stats_bcodes = 0 +stats_quotes = 0 +stats_parags = 0