[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 !
|
# 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]
|
## [1.9.14]
|
||||||
- added 'check' process on block-codes
|
- added 'check' process for block-codes
|
||||||
|
|
||||||
## [1.9.13]
|
## [1.9.13]
|
||||||
- Check: One-Line needed tags, titles
|
- Check: One-Line needed tags, titles
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Version: 1.9.14
|
# Version: 1.9.15
|
||||||
# Updated: 2023-10-01 1696152727
|
# Updated: 2023-10-02 1696231003
|
||||||
# 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>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -73,12 +73,11 @@ def manage(action, target):
|
||||||
def is_article(target):
|
def is_article(target):
|
||||||
valid(target)
|
valid(target)
|
||||||
|
|
||||||
print("pass", post.error, args.targets)
|
|
||||||
print("chk_date", chk_date)
|
print("chk_date", chk_date)
|
||||||
|
print()
|
||||||
print("Stats coms =", post.stats_tyto_coms, post.stats_html_coms)
|
print("Final text_contents string")
|
||||||
print("Titles =", post.stats_titles)
|
for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines):
|
||||||
|
print(">", ln, line)
|
||||||
|
|
||||||
#===========================================#
|
#===========================================#
|
||||||
# Check full article contents (head + text) #
|
# Check full article contents (head + text) #
|
||||||
|
@ -97,7 +96,9 @@ def valid(target):
|
||||||
|
|
||||||
# Text article
|
# 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)
|
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 #
|
# Create new post.text_contents #
|
||||||
# Return True/False #
|
# Return True/False #
|
||||||
#---------------------------------------#
|
#---------------------------------------#
|
||||||
def bcodes():
|
def sl_paired(markers):
|
||||||
new_text_contents = ""
|
new_text_contents = ""
|
||||||
opened = closed = False
|
opened = closed = in_tag = False
|
||||||
closed_bcodes_nbr = 0 # To compare with post.stats_bcodes
|
stats_opened = stats_closed = 0
|
||||||
|
tags = ()
|
||||||
|
|
||||||
for ln, line in enumerate(post.text_contents.rsplit("\n"),
|
if markers == "bcodes" : tags = post.bcodes
|
||||||
post.head_lines + 1):
|
elif markers == "quotes" : tags = post.quotes
|
||||||
|
elif markers == "parags" : tags = post.parags
|
||||||
|
|
||||||
# Opened tag
|
# loop lines in text_contents
|
||||||
if line.startswith(post.bcodes[0]):
|
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:
|
if opened:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(53, "%s) %s ... %s"%(
|
debug.out(53, "%s) %s ... %s"%(
|
||||||
ln,
|
ln,
|
||||||
post.bcodes[0], post.bcodes[1]
|
tags[0], tags[1]
|
||||||
), post.uri, True, 2, False)
|
), post.uri, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
opened = in_tag = True
|
||||||
|
closed = False
|
||||||
|
stats_opened += 1
|
||||||
|
|
||||||
opened = True
|
# Tag is closed
|
||||||
post.stats_bcodes += 1
|
if line.startswith(tags[1]):
|
||||||
continue
|
# Tag was already closed
|
||||||
|
|
||||||
# Close tag
|
|
||||||
elif line.startswith(post.bcodes[1]):
|
|
||||||
if closed:
|
if closed:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(53, "%s) %s ... %s"%(
|
debug.out(53, "%s) %s ... %s"%(
|
||||||
ln,
|
ln,
|
||||||
post.bcodes[0], post.bcodes[1]
|
tags[0], tags[1]
|
||||||
), post.uri, True, 2, False)
|
), post.uri, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
closed = True
|
closed = True
|
||||||
closed_bcodes_nbr += 1
|
opened = False
|
||||||
|
stats_closed += 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
|
|
||||||
|
|
||||||
|
if in_tag:
|
||||||
# Contents must be indented
|
# Contents must be indented
|
||||||
if opened and not closed:
|
if not line.startswith(tags):
|
||||||
if len(line) - len(line.lstrip()) < 3:
|
if len(line) - len(line.lstrip()) < 3:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(54, "%s) %s..."%(ln, line[0:10]), post.uri, True, 2, False)
|
debug.out(54, "%s) %s..."%(ln, line[0:10]), post.uri, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
line = ""
|
||||||
|
|
||||||
# Create new string
|
# Create new string, removing in_tag line if in bcodes or quotes
|
||||||
if not opened and not closed:
|
if markers in post.raw_contents:
|
||||||
if not new_text_contents: new_text_contents = line
|
if not new_text_contents: new_text_contents = line
|
||||||
else: new_text_contents = "%s\n%s"%(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
|
|
||||||
|
|
||||||
post.text_contents = new_text_contents
|
post.text_contents = new_text_contents
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ def is_tyto_format():
|
||||||
error = debug.out(23, "?", uri, True, 2, False)
|
error = debug.out(23, "?", uri, True, 2, False)
|
||||||
return 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
|
text_lines = lines - head_lines
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -180,6 +180,9 @@ bcodes = ("{{", "}}")
|
||||||
quotes = ("[[", "]]")
|
quotes = ("[[", "]]")
|
||||||
parags = ("((", "))")
|
parags = ("((", "))")
|
||||||
|
|
||||||
|
# markers with "protected" contents
|
||||||
|
raw_contents = ("bcodes", "quotes")
|
||||||
|
|
||||||
# Comments
|
# Comments
|
||||||
text_comments = (";;", "<!--")
|
text_comments = (";;", "<!--")
|
||||||
html_comment = { text_comments[0] : "<!-- %s -->" }
|
html_comment = { text_comments[0] : "<!-- %s -->" }
|
||||||
|
@ -200,3 +203,5 @@ stats_tyto_coms = 0
|
||||||
stats_html_coms = 0
|
stats_html_coms = 0
|
||||||
stats_titles = 0
|
stats_titles = 0
|
||||||
stats_bcodes = 0
|
stats_bcodes = 0
|
||||||
|
stats_quotes = 0
|
||||||
|
stats_parags = 0
|
||||||
|
|
Loading…
Reference in New Issue