wip: added "_brut:" converter

This commit is contained in:
Cyrille L 2022-11-22 14:59:12 +01:00
parent 6f3de302ee
commit d24600f1eb
1 changed files with 58 additions and 7 deletions

View File

@ -104,14 +104,17 @@ def manage_wip(file_post, Force):
if links_u > 0: wip_links( wip_html)
if quotes > 0: wip_quotes( wip_html.rsplit('\n'))
# brut files
if bruts_u > 0: wip_bruts( wip_html.rsplit('\n'))
# Get Legacy contents from base64 markers
convert_all_b64(wip_html.rsplit('\n'))
print('> Article HTML:')
print(wip_html)
#print('> Article HTML:')
#print(wip_html)
#print('> Article with Tabs:')
#tab_article(wip_html.rsplit('\n'))
print('> Article with Tabs:')
tab_article(wip_html.rsplit('\n'))
@ -553,6 +556,55 @@ def wip_images(article):
else : wip_html = line
#=============================================#
# Convert line _brut: to pre HTML, like bCode #
#---------------------------------------------#
def wip_bruts(article):
global wip_html
wip_html = ''
all_vars = set(globals())
for var in all_vars:
if var.startswith('brut_'):
brut = globals()[var]
# Search in article lines for _image:
for line in article:
if not line.startswith('_brut:'):
if wip_html: wip_html = '%s\n%s'%(wip_html, line)
else : wip_html = line
elif line.startswith('_brut:%s'%brut[0]):
# Open target file
brut_file = ''
brut_html = '' # brut file contents
brut_uri = brut[1][1:len(brut[1])] # No need first "/"
brut_file = '%s%s'%(domain.domain_articles, brut_uri)
brut_datas = open(brut_file, 'r').read()
# Convert each lines to HTML, add to string
for ln, bline in enumerate(brut_datas.rsplit('\n'), 1):
brut_line_html = '<span class="ln">%s</span>'%ln + \
'<span class="brut">%s</span>'%bline
if brut_html: brut_html = '%s\n%s'%(brut_html,brut_line_html)
else : brut_html = brut_line_html
# Get CSS, if exists, before creating last brut_html
get_css(line)
# Add first and last HTML tags to string
brut_html = '<pre class="%s" title="%s">\n'%(
css_set, brut[2]) + \
'%s\n</pre>'%brut_html
# Replace line
if wip_html: wip_html = '%s\n%s'%(wip_html, brut_html)
else : wip_html = brut_html
#=========================#
# Done when command check #
# - convert_bcodes() #
@ -589,9 +641,8 @@ def convert_bcodes(article, fm, lm, css):
if bCode:
bCode_ln += 1
line = '<span class="lnbr">%s</span><span>%s</span>'%(
bCode_ln, line
)
line = '<span class="ln">%s</span>'%bCode_ln + \
'<span class="brut">%s</span>'%line
if bCode_lines: bCode_lines = '%s\n%s'%(bCode_lines, line)
else : bCode_lines = line
else: