Spaces:
Sleeping
Sleeping
Download app_modules/utils.py from IELTS8/ISF: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/IELTS8/ISF/resolve/main/app_modules/utils.py
- Command line
-
hf download hf://spaces/IELTS8/ISF/app_modules/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/IELTS8/ISF/resolve/main/app_modules/utils.py
1.05 kB
| import re | |
| def convert_to_markdown(text): | |
| text = text.replace("$", "$") | |
| def replace_leading_tabs_and_spaces(line): | |
| new_line = [] | |
| for char in line: | |
| if char == "\t": | |
| new_line.append("	") | |
| elif char == " ": | |
| new_line.append(" ") | |
| else: | |
| break | |
| return "".join(new_line) + line[len(new_line):] | |
| markdown_text = "" | |
| lines = text.split("\n") | |
| in_code_block = False | |
| for line in lines: | |
| if in_code_block is False and line.startswith("```"): | |
| in_code_block = True | |
| markdown_text += f"{line}\n" | |
| elif in_code_block is True and line.startswith("```"): | |
| in_code_block = False | |
| markdown_text += f"{line}\n" | |
| elif in_code_block: | |
| markdown_text += f"{line}\n" | |
| else: | |
| line = replace_leading_tabs_and_spaces(line) | |
| line = re.sub(r"^(#)", r"\\\1", line) | |
| markdown_text += f"{line} \n" | |
| return markdown_text | |