[1.9.15] - Added 'check' process for bcodes, quotes and paragraphs
This commit is contained in:
parent
2a8cdf0084
commit
17495bd7af
|
@ -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
|
||||
|
|
|
@ -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 <echolib+tyto@a-lec.org>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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 = (";;", "<!--")
|
||||
html_comment = { text_comments[0] : "<!-- %s -->" }
|
||||
|
@ -200,3 +203,5 @@ stats_tyto_coms = 0
|
|||
stats_html_coms = 0
|
||||
stats_titles = 0
|
||||
stats_bcodes = 0
|
||||
stats_quotes = 0
|
||||
stats_parags = 0
|
||||
|
|
Loading…
Reference in New Issue