From 17495bd7afa361c0e4874e79c4c9b78b9b022b3e Mon Sep 17 00:00:00 2001 From: Cyrille LOUARN Date: Mon, 2 Oct 2023 09:19:20 +0200 Subject: [PATCH] [1.9.15] - Added 'check' process for bcodes, quotes and paragraphs --- CHANGELOG.md | 7 +- src/usr/bin/tyto | 4 +- .../program/__pycache__/check.cpython-311.pyc | Bin 10793 -> 10853 bytes .../program/__pycache__/post.cpython-311.pyc | Bin 4874 -> 4968 bytes src/var/lib/tyto/program/check.py | 107 +++++++++--------- src/var/lib/tyto/program/post.py | 7 +- 6 files changed, 67 insertions(+), 58 deletions(-) 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 40f97f221db71f454bec5fc3a17d91d982a88883..66120bebf1d69353a9795525a56e5012fd1417a5 100644 GIT binary patch delta 3178 zcmcguO>7&-72Y52E|(O4M2R9zQ4%HVZxvCAQQL6rSVa^?tpVAN6D2M3QMX^MJV zzwUcT&#_MZgv+V_4c^~0JM|+Lm;SEk;%Q11C`vD|?fN4H=7Ynbv3N3? z2&u7G)W~Eism7A35>iwWPo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vgoLYNOru@^@FZ;*IIl2!dhoh8YoEv71ZNl-;)Ll(qPpH`D4bTZJyek+6-?j=HV%Lj{PS5>oa$icTc@LU$mSrSV_k2O%;TNaE4n2+XBIr?VT0GnZw*W;ev0t=o>B%o+ucu&OFER)M1e^B4lYEVhvKoP0VQ_>23rXE-6m^KAf|@g4^_P&xFlQ3gF*=D?r1Q6uL~~7vMR?YRE)C2C=hnDM-TM|J7kvH*-fB!(`SOYu0REuxhfoTaHCuW Y?ZW~3kKnnc5sm`~+lMdEGoR}C59DIi>i_@% 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 44dee06b22bd302223d85cb6a40cecd419334241..9ba86feb4766d1b96ec2e4eb7a7dce4e5a1baca2 100644 GIT binary patch delta 291 zcmeBDd!fd+oR^o20SI>GNTr&KP2`hcJTy_gHYi0fN-R|@g+US|2L>rZnT%25DZ)__ zDIzJNDPk$&DH18db6BG!Qy8M8fLI!cWq?=~h~P61QgVJuYVj?$!qWVb z)Z)o30*4qCCLb5blrQoInpWfkByO=4Bo-y67vJJ3N-U30&d)1J%`2JgE?6dgi>J6G zv7|U2q8Y{mtDd|^P?{?qsGAXpi;X5f6uinJpwhrId9#q8@C_m11|Bfcz|+7}qzY65 E0J-*3^#A|> delta 189 zcmaE%)}_X`oR^o20SHv|BvUtvPUMqd+%{3Y)-F{vg+US|4hAWLnT%0lDMC@=DZ(it zDWWN2DdH(Yb6BG!QW&BnfmjNNrGZ!`g)x{xQ)1&gB{s%&n+4f>nKm!sWMyPrzIheb zOvcR~JXe_~>kAxUl%4!RAXEGnTT*gfw!+f<5)fUGSd^GPxk9jPGMA7PR}9c{ aMj$R$oUA8wbuyQ*H)jJ+15c4EPz(S", 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