(input_str, lang="")
| 154 | |
| 155 | |
| 156 | def 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 | |
| 185 | def get_repo_name(): |
no test coverage detected