From 1b13f8e1dfd4416da2db18b8bdd44cc1ba0f8d97 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Tue, 18 Apr 2023 12:32:14 +0200 Subject: [PATCH] [0.10.2] --- CHANGELOG.md | 5 ++++ README.md | 4 +-- debian/control | 2 +- src/usr/bin/tyto | 2 +- src/var/lib/tyto/program/check.py | 47 ++++++++++++++++++++----------- src/var/lib/tyto/program/tyto.py | 40 +++++++++++++++----------- src/var/lib/tyto/program/wip.py | 40 +++++++++++++------------- 7 files changed, 84 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc26f21..8ccc2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ Tyto - Littérateur - Changelog: https://git.a-lec.org/echolib/tyto-litterateur/-/blob/master/CHANGELOG.md - License: https://git.a-lec.org/echolib/tyto-litterateur/-/blob/master/LICENSE +## [0.10.2] +- Citer dans un texte > `[_` + `_]` +- Italique `` > `;_` + `_;` +- Italique `` > {_:_` + `_:` + ## [0.10.1] - Fix with try in check for static page diff --git a/README.md b/README.md index 4838990..c4660b0 100644 --- a/README.md +++ b/README.md @@ -149,10 +149,10 @@ Vous pouvez avoir un Nom identique pour les marqueurs `file:` et `link:` ``` *_très gras_* # +_gras léger_+ # -/_en italique_/ # +;_en italique_; # :_en italique_: # ~_texte barré_~ # -@_Citation rapide_@ # +[_Citation rapide_] # %_Classe personnalisée_% >>> ._Souligné_. # {_Code_} # diff --git a/debian/control b/debian/control index 066e25c..77c6364 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: tyto -Version: 0.10.1 +Version: 0.10.2 Section: custom Priority: optional Architecture: all diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 042c35d..e4e7998 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Version: 0.10.1 +# Version: 0.10.2 # Tyto - Littérateur # # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 5ecd487..144d08b 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -343,19 +343,19 @@ def if_icodes_bcodes_quotes(post_bottom): continue # quotes - elif line.startswith(tyto.words_tags[11][0]) and not in_bcode: + elif line.startswith(tyto.block_tags[1][0]) and not in_bcode: quote = in_quote = in_bq = True continue - elif line.startswith(tyto.words_tags[11][1]): + elif line.startswith(tyto.block_tags[1][1]): in_quote = False nbr_quotes += 1 continue # bcode - elif line.startswith(tyto.words_tags[12][0]) and not in_quote: + elif line.startswith(tyto.block_tags[2][0]) and not in_quote: bcode = in_bcode = in_bq = True continue - elif line.startswith(tyto.words_tags[12][1]): + elif line.startswith(tyto.block_tags[2][1]): in_bcode = False nbr_bcodes += 1 continue @@ -781,14 +781,29 @@ def check_content(post_bottom): for tag in tyto.words_tags: c_opened = c_closed = 0 - if tag[5] == 'w': - c_opened = post_bottom.count(tag[0]) - c_closed = post_bottom.count(tag[1]) - # Useless tag now, replace - post_bottom = post_bottom.replace(tag[0], '') - post_bottom = post_bottom.replace(tag[1], '') - elif tag[5] == 't': - for line in post_bottom.rsplit('\n'): + c_opened = post_bottom.count(tag[0]) + c_closed = post_bottom.count(tag[1]) + # Useless tag now, replace + post_bottom = post_bottom.replace(tag[0], '') + post_bottom = post_bottom.replace(tag[1], '') + + if c_opened != c_closed: + logs.out("8", '%s "%s" + "%s" > %s'%( + tag[4], tag[0], tag[1], db.uri_file + ), False) + post_err = True + + else: + globals()['post_%s'%tag[4]] = int(c_opened) + + + # Check block tags paragraphs, qyotes...) + # Set stats for each one + #------------------------------------------- + for tag in tyto.block_tags: + c_opened = c_closed = 0 + + for line in post_bottom.rsplit('\n'): if line.startswith(tag[0]): c_opened += 1 if line.startswith(tag[1]): c_closed += 1 @@ -797,7 +812,7 @@ def check_content(post_bottom): tag[4], tag[0], tag[1], db.uri_file ), False) post_err = True - return # Useless and could code errors to check nexts + else: globals()['post_%s'%tag[4]] = int(c_opened) @@ -813,10 +828,10 @@ def check_content(post_bottom): if post_lists > 0: inlist = False for ln, line in enumerate(post_bottom.rsplit('\n'), 1): - if line.startswith(tyto.words_tags[13][0]): + if line.startswith(tyto.block_tags[3][0]): inlist = True continue - elif line.startswith(tyto.words_tags[13][1]): + elif line.startswith(tyto.block_tags[3][1]): inlist = False if not inlist: @@ -825,7 +840,7 @@ def check_content(post_bottom): if inlist and not line or not line[0] in tyto.markers_lists: logs.out("3", 'L=%s. %s %s > %s'%( ln + ln_header, - tyto.words_tags[13][4], + tyto.block_tags[3][4], tyto.markers_lists, db.uri_file ), False) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 01b4c57..8a33bb7 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -105,21 +105,29 @@ headers = \ # [6] = Check content differently. 't' = startswith #------------------------------------------------------------- words_tags = [ -('>_', '_<', '', '', 'anchors', 'w'), +('>_', '_<', + '', + '', 'anchors', 'w' +), ('*_', '_*', '', '', 'strongs', 'w'), ('+_', '_+', '', '', 'bolds', 'w'), -('/_', '_/', '', '', 'emphasis', 'w'), +(';_', '_;', '', '', 'emphasis', 'w'), (':_', '_:', '', '', 'italics', 'w'), ('~_', '_~', '', '', 'dels', 'w'), ('._', '_.', '', '', 'underlines', 'w'), -('@_', '_@', '', '', 'cites', 'w'), +('[_', '_]', '', '', 'cites', 'w'), ('%_', '_%', '', '', 'customs', 'w'), ('{_', '_}', '', '', 'codes', 'w'), -('((', '))', '

', '

', 'paragraphs', 't'), -('[[', ']]', '[[', ']]', 'quotes', 't'), -('{{', '}}', '{{', '}}', 'bcodes', 't'), -('-(', '-)', '-(', '-)', 'lists', 't'), -('<<', '>>', '
', '
', 'div', 't') +] + +# At begining line, create block contents +block_tags = \ +[ +('((', '))', '

', '

', 'paragraphs'), +('[[', ']]', '[[', ']]', 'quotes'), +('{{', '}}', '{{', '}}', 'bcodes'), +('-(', '-)', '-(', '-)', 'lists'), +('<<', '>>', '
', '
', 'div'), ] # Tags that do not need to be paired @@ -132,10 +140,10 @@ single_tags = [ # When counting words, do no count line starting with: nolinewords = \ ( -words_tags[10][0], words_tags[10][1], # paragraphs -words_tags[11][0], words_tags[11][1], # quotes -words_tags[12][0], words_tags[12][1], # bcodes -words_tags[13][0], words_tags[13][1], # lists +block_tags[0][0], block_tags[0][1], # paragraphs +block_tags[1][0], block_tags[1][1], # quotes +block_tags[2][0], block_tags[2][1], # bcodes +block_tags[3][0], block_tags[3][1], # lists single_tags[0][0], single_tags[1][0], # New line, anchor '_%s:'%opt_header_tags[1], '_%s:'%opt_header_tags[4], # _image:, _raw: '_%s:'%opt_header_tags[5] # _code @@ -328,10 +336,10 @@ def protect_bcodes_quotes(process, post_bottom): #---------------------- # Bcode (at close, replace with base64) if not in_quote: - if line.startswith(words_tags[12][0]): # Open + if line.startswith(block_tags[2][0]): # Open start_bcode = True in_bcode = True - elif line.startswith(words_tags[12][1]): # Close + elif line.startswith(block_tags[2][1]): # Close close_bcode = True in_bcode = False if process == "wip": @@ -342,10 +350,10 @@ def protect_bcodes_quotes(process, post_bottom): # Quote (at close, replace with base64) if not in_bcode: - if line.startswith(words_tags[11][0]): # Open + if line.startswith(block_tags[1][0]): # Open start_quote = True in_quote = True - elif line.startswith(words_tags[11][1]): # Close + elif line.startswith(block_tags[1][1]): # Close close_quote = True in_quote = False if process == "wip": diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 42722c6..47c56da 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -311,27 +311,27 @@ def wip_words_tags(): for ln, line in enumerate(post_bottom.rsplit('\n')): # Paragraphs Open tag if db.paragraphs > 0: - if line.startswith(tyto.words_tags[10][0]): + if line.startswith(tyto.block_tags[0][0]): set_css = tyto.get_css(line) replace_in_post(post_bottom.rsplit('\n')[ln], - tyto.words_tags[10][2]%set_css + tyto.block_tags[0][2]%set_css ) # Close paragraph tag - elif line.startswith(tyto.words_tags[10][1]): + elif line.startswith(tyto.block_tags[0][1]): replace_in_post(line, - tyto.words_tags[10][3] + tyto.block_tags[0][3] ) # div Open tag - if line.startswith(tyto.words_tags[14][0]): + if line.startswith(tyto.block_tags[4][0]): set_css = tyto.get_css(line) replace_in_post(post_bottom.rsplit('\n')[ln], - tyto.words_tags[14][2]%set_css + tyto.block_tags[4][2]%set_css ) # Close paragraph tag - elif line.startswith(tyto.words_tags[14][1]): + elif line.startswith(tyto.block_tags[4][1]): replace_in_post(line, - tyto.words_tags[14][3] + tyto.block_tags[4][3] ) # Open anchors link @@ -541,7 +541,7 @@ def wip_quotes() : for qline in quote: # Begin marker quote [11] - if qline.startswith(tyto.words_tags[11][0]): + if qline.startswith(tyto.block_tags[1][0]): set_css = tyto.get_css(qline) continue @@ -550,7 +550,7 @@ def wip_quotes() : # Paragraph [10] Open # Construct quote_html - if qline.startswith(tyto.words_tags[10][0]): + if qline.startswith(tyto.block_tags[0][0]): par_css = tyto.get_css(qline) # Set tabulation for paragraphs and content @@ -559,7 +559,7 @@ def wip_quotes() : # Replace opened paragrph with html line qline_html = '%s%s'%( - tab_p * ' ', tyto.words_tags[10][2]%par_css + tab_p * ' ', tyto.block_tags[0][2]%par_css ) # Add line to quote_html @@ -570,16 +570,16 @@ def wip_quotes() : continue # Paragraph Close - if qline.startswith(tyto.words_tags[10][1]): + if qline.startswith(tyto.block_tags[0][1]): # Replace closed paragrph with html line - qline_html = tyto.words_tags[10][3] + qline_html = tyto.block_tags[0][3] quote_html = '%s\n%s%s'%( quote_html, int(tab_p) * ' ', qline_html ) continue # End of marker quote - if qline.startswith(tyto.words_tags[11][1]): + if qline.startswith(tyto.block_tags[1][1]): continue # Add other lines @@ -694,14 +694,14 @@ def wip_bcodes(): # Convert src_bcode for line in src_bcode.rsplit('\n'): # CSS + opened marker - if line.startswith(tyto.words_tags[12][0]): + if line.startswith(tyto.block_tags[2][0]): set_css = tyto.get_css(line) html_bcode = \ '\n'%set_css + \ '
'
       
       # closed marker
-      elif line.startswith(tyto.words_tags[12][1]):
+      elif line.startswith(tyto.block_tags[2][1]):
         html_bcode = \
         '%s\n  
\n'%html_bcode + \ '
' @@ -829,7 +829,7 @@ def wip_lists(): for line in post_bottom.rsplit('\n'): # Open list - if line.startswith(tyto.words_tags[13][0]): + if line.startswith(tyto.block_tags[3][0]): block_list = content_list = '' css = tyto.get_css(line) in_list = True @@ -837,7 +837,7 @@ def wip_lists(): continue # Close list - elif line.startswith(tyto.words_tags[13][1]): + elif line.startswith(tyto.block_tags[3][1]): in_list = False block_list = '%s\n%s'%(block_list, line) html_list = convert_list( @@ -909,8 +909,8 @@ def convert_list(markdown_str): work_str = "" for i in range(len(items)): - if tyto.words_tags[13][0] in items[i] or \ - tyto.words_tags[13][1] in items[i]: + if tyto.block_tags[3][0] in items[i] or \ + tyto.block_tags[3][1] in items[i]: continue rank = cur_rank