MCPcopy
hub / github.com/ChinaGodMan/UserScripts / format_str

Function format_str

utils/helper.py:156–182  ·  view source on GitHub ↗
(input_str, lang="")

Source from the content-addressed store, hash-verified

154
155
156def format_str(input_str, lang=""):
157 settings = read_json('utils/docs/settings.json')
158
159 # 提取脚本列表标记点
160 readme_start_tag = "<!--README-TOC-->"
161 readme_end_tag = "<!--README-TOC-END-->"
162 toc = get_file_description(f'docs/{lang}/README.md', readme_start_tag, readme_end_tag)
163 last_line = toc.strip().split('\n')[-1]
164 match = re.search(r"#(.+?)\)", last_line)
165 scripts_list_mark = match.group(1)
166 scripts_list_mark = urllib.parse.quote(scripts_list_mark)
167
168 placeholders = {
169 'repo_name': settings['repository'],
170 'sub_repo_name': settings['sub_repository'],
171 'separator': settings['separator'],
172 'greasyfork_user_id': str(settings['greasyfork_user_id']),
173 'scripts_list': scripts_list_mark,
174 'lang_code': lang
175 }
176
177 def replacer(match):
178 key = match.group(1)
179 return placeholders.get(key, match.group(0))
180 pattern = re.compile(r'{([^}]+)}')
181 formatted_str = pattern.sub(replacer, input_str)
182 return formatted_str
183
184
185def get_repo_name():

Callers 6

get_new_contentFunction · 0.90
get_new_contentFunction · 0.90
generate_html_contentFunction · 0.90
generate_descriptionFunction · 0.90
generate_html_tableFunction · 0.90
generate_grouped_htmlFunction · 0.90

Calls 2

get_file_descriptionFunction · 0.90
read_jsonFunction · 0.85

Tested by

no test coverage detected