diff --git a/README.md b/README.md index 6a2121e..d6e14ae 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,19 @@ un long paragraphe ### Lien vers URL ``` -Voir ce _Nom du lien +Voir ce _Nom du lien # Ouverture même fenêtre +Voir ce _Nom du lien+ # ouverture nouvelle fenêtre ``` ### Lien vers fichier ``` -Voir ce __Nom du lien +Voir ce __Nom du lien # Ouverture même fenêtre +Voir ce __Nom du lien+ # ouverture nouvelle fenêtre ``` +Note: +Vous pouvez avoir un NAME identique pour file: et link: + ### Gras, Strong, italique... ``` *_très gras_* # @@ -148,11 +153,11 @@ Avec ce NOM. # affichage les une à côté des autres _image:NOM _image:NOM c=CSS -_image:NOM c=CSS w=1080 +_image:NOM c=css w=1080 _image:NOM w=640em h=480em -_image:NOM t= <<< Rend l'image interne cliquable -_image:NOM t=https://... -_image:NOM c=CSS t=https:// w=320px h=240 +_image:NOM t=+ # Rend l'image interne cliquable +_image:NOM t=https://...# Donne un lien à l'image +_image:NOM c=CSS t=https://... w=320px h=240 ``` ### Code Brut depuis un fichier diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 6751e9a..85af71c 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -277,8 +277,9 @@ def check_headers(post_header): post_err = True if not post_err: - web_link = '%s'%( - 'link', link_url, link_alt, link_name + web_link = '%s'%( + '%s', link_alt, link_name ) globals()['link_%s'%stat_links] = ( '_%s'%link_name, web_link @@ -388,8 +389,9 @@ def check_headers(post_header): post_err = True if not post_err: - web_link = '%s'%( - 'file', web_uri, file_alt, file_name + web_link = '%s'%( + '%s', file_alt, file_name ) globals()['file_%s'%stat_files] = ( '__%s'%file_name, web_link diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 38d3a1f..696f48c 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -16,7 +16,7 @@ #---------------------------------------------------------------------- #********************************************************************** -import os +import os, re import tyto def manage_wip(target, option): @@ -84,7 +84,8 @@ def wip_article(target): # Convert contents from modules wip_single_tags() # br /, anchors wip_words_tags() # Paragraphs, strongs, italics - wip_links() # Links from headers in DB + wip_links() # Links_%i from headers in DB + wip_images() # Images_%i from headers in DB print(article_bottom) @@ -172,17 +173,95 @@ def wip_words_tags(): def wip_links(): global article_bottom - if uniq_links > 0: - for i in range(1, uniq_links + 1): - link = 'link_%s'%i - article_bottom = article_bottom.replace( - eval(link)[0], eval(link)[1] - ) - + # Doing files, first, becase of similar marker if uniq_files > 0: for i in range(1, uniq_files + 1): file = 'file_%s'%i article_bottom = article_bottom.replace( - eval(file)[0], eval(file)[1] + eval(file)[0]+'+', eval(file)[1]%('_blank') + ) + article_bottom = article_bottom.replace( + eval(file)[0], eval(file)[1]%('_self') ) + if uniq_links > 0: + for i in range(1, uniq_links + 1): + link = 'link_%s'%i + article_bottom = article_bottom.replace( + eval(link)[0]+'+', eval(link)[1]%('_blank') + ) + article_bottom = article_bottom.replace( + eval(link)[0], eval(link)[1]%('_self') + ) + +#-------------------------------------# +# Get width and height for image # +# from parameter c=, from wip_image() # +#-------------------------------------# +def get_wh_image(value): + sizes = re.findall(r'(\d+)|(\D+)', value) + if not sizes[0][1]: return('%spx'%value) + else: return(value) + +#=================================# +# Find all _image, get parameters # +# Convert _images:%name to HTML # +#---------------------------------# +def wip_images(): + global article_bottom + + if uniq_images > 0: + image_link = '%s' + image_show = '%s' + + for ln, line in enumerate(article_bottom.rsplit('\n')): + if line.startswith('_image:'): + values = line.rsplit(' ') + #print(values) + + for i in range(1, uniq_images + 1): + image = 'image_%s'%i + target = width = height = False + set_css = tyto.domain_css + '_image' + + if eval(image)[0] == values[0]: + for value in values: + if 't=' in value: + target = value.rsplit('=',1)[1] + if target == "+": image_target = eval(image)[1] + else: image_target = target + + if 'c=' in value: + set_css = value.rsplit('=', 1)[1] + + if 'w=' in value: + width = get_wh_image(value.rsplit('=',1)[1]) + + if 'h=' in value: + height = get_wh_image(value.rsplit('=',1)[1]) + + if width and height: + style = ' style="width:%s;height=%s"'%(width, height) + elif width: + style = ' style="width:%s"'%width + elif height: + style = ' style="height:%s"'%height + else: + style = '' + + image_src = image_show%( + set_css, eval(image)[1], eval(image)[2], style + ) + + if target: + image_tgt = image_link%( + set_css, image_target, eval(image)[2], '%s' + ) + else: + image_tgt = '%s' + + image_html = image_tgt%image_src + + article_bottom = article_bottom.replace( + article_bottom.rsplit('\n')[ln], image_html + )