stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
a30365a2d653297d6fffae202aa12cb8f08a175e
parent
0aa85fe15d632ac20256510674352aede226cd2b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-03-29 16:53
preserve lines in ctpl

Diffstat

M ctpl.py 13 ++++++++-----

1 files changed, 8 insertions, 5 deletions


diff --git a/ctpl.py b/ctpl.py

@@ -21,12 +21,14 @@ def tokenize(s):
   21    21 
   22    22 def print_safe(s, args, indent):
   23    23 	if args:
   24    -1 		print(indent + 'fprintf(fp, "%s", %s);' % (s, ', '.join(args)))
   -1    24 		return ['fprintf(fp, "%s", %s);' % (s, ', '.join(args))]
   25    25 	elif s:
   26    -1 		print(indent + 'fputs("%s", fp);' % s)
   -1    26 		return ['fputs("%s", fp);' % s]
   -1    27 	return []
   27    28 
   28    29 
   29    30 def parse_line(indent, tpl):
   -1    31 	lines = []
   30    32 	s = ''
   31    33 	args = []
   32    34 	for is_text, token in tokenize(tpl):
@@ -37,7 +39,7 @@ def parse_line(indent, tpl):
   37    39 			s += placeholder
   38    40 			args.append(arg)
   39    41 		else:
   40    -1 			print_safe(s, args, indent)
   -1    42 			lines += print_safe(s, args, indent)
   41    43 			s = ''
   42    44 			args = []
   43    45 
@@ -47,9 +49,10 @@ def parse_line(indent, tpl):
   47    49 				arg = token
   48    50 				l = 'strlen(%s)' % token
   49    51 
   50    -1 			print(indent + 'xmlencode(fp, %s, %s);' % (arg, l))
   -1    52 			lines.append('xmlencode(fp, %s, %s);' % (arg, l))
   -1    53 	lines += print_safe(s, args, indent)
   51    54 
   52    -1 	print_safe(s, args, indent)
   -1    55 	print(indent + ' '.join(lines))
   53    56 
   54    57 
   55    58 if __name__ == '__main__':