Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from lcdoc.tools import exists, read_file, write_file, hostname, time, os, sys, app lppytest
3auto_gen_cmt = '''
4<!-- AUTOMATICALLY GENERATED FILE - DO NOT DIRECTLY EDIT!
6Direct edits will be gone after next CI build.
7By: %s@%s (%s)
8Command Line:
10 %s
11-->
12'''
15def mark_auto_created(fn): lppytest
17 if exists(fn):
18 s = read_file(fn)
19 else:
20 s = fn
21 h = auto_gen_cmt % (
22 os.environ.get('USER'),
23 hostname(),
24 time.ctime(),
25 ' '.join(sys.argv).replace(' -', ' \\\n -'),
26 )
27 s = h.lstrip() + '\n' + s
28 if exists(fn):
29 write_file(fn, s)
30 app.info('Marked content as autocreated')
31 return s
34class Mkdocs: lppytest
35 details = '''
37<details>
38 <summary>%s</summary>
40%s
42</details>
44'''
45 code_ = '''
47```_code_
48%s
49```
51 '''
52 admon_ = '''
54!!! %s "%s"
56%s
58 '''
59 admon_closed_ = admon_.replace('!!!', '???') lppytest
60 admon_clsabl_ = admon_.replace('!!!', '???+') lppytest
61 tab_ = '''
62=== "%s"
64%s
66 '''
67 js = code_.replace('_code_', 'js') lppytest
68 py = code_.replace('_code_', 'python') lppytest
70 code = lambda which, body: Mkdocs.code_.replace('_code_', which) % body 70 ↛ exitline 70 didn't run the lambda on line 70lppytest
71 tab = lambda title, cont, t=tab_: t % (title, indent(cont)) 71 ↛ exitline 71 didn't run the lambda on line 71lppytest
72 admon = lambda title, cont, mode='note', widg=admon_: widg % ( 72 ↛ exitline 72 didn't run the lambda on line 72lppytest
73 mode,
74 title.replace('\n', ''),
75 indent(cont),
76 )
77 closed_admon = lambda *a, _=admon, __=admon_closed_, **kw: _(*a, widg=__, **kw) 77 ↛ exitline 77 didn't run the lambda on line 77lppytest
78 clsabl_admon = lambda *a, _=admon, __=admon_clsabl_, **kw: _(*a, widg=__, **kw) 78 ↛ exitline 78 didn't run the lambda on line 78lppytest
81indent = lambda s: ('\n' + s).replace('\n', '\n ')[1:] 81 ↛ exitline 81 didn't run the lambda on line 81lppytest
84def deindent(
85 s, add_code_line_seps=False, dl=lambda l, ws: l[ws:] if l[:ws] == ' ' * ws else l
86):
87 # can handle first line not indentend as in docstrings starting after """ w/o line sep
88 s = s or '' lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/show_src/index.md
89 if not s.strip(): 89 ↛ 90line 89 didn't jump to line 90, because the condition on line 89 was never truelp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/show_src/index.md
90 return s
91 ls = s.splitlines() lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/show_src/index.md
92 # first line might be special after like '''def foo'''
93 # if indented though we use it:
94 if len(ls) == 1: lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/show_src/index.md
95 return ls[0].strip() lp|features/lp/plugs/lightbox/index.md
96 if ls[0].startswith(' ') or ls[0][:4] in ('def ', 'clas'): lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
97 i = 0 lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.md
98 else:
99 for i in 1, 2, 3, 4: 99 ↛ 106line 99 didn't jump to line 106, because the loop on line 99 didn't completelp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
100 if i > len(ls) - 1: 100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never truelp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
101 i = i - 1
102 break
103 if ls[i].lstrip(): lp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
104 break lp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
105 # len of indent to remove:
106 ws = len(ls[i]) - len(ls[i].lstrip()) lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
107 ls = [dl(l, ws) for l in ls] lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
108 if add_code_line_seps: 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never truelp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
109 ls = line_sep_before_code(ls)
110 return '\n'.join(ls).strip() lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/show_src/index.md
113def line_sep_before_code(ls): lppytest
114 """for markdown"""
115 r, is_code = [], False
116 for ln in ls:
117 if not is_code:
118 if ln.startswith(' '):
119 r.append('')
120 is_code = True
121 else:
122 if not ln.startswith(' '):
123 is_code = False
124 r.append(ln)
125 return r