(text: str, params: Dict[str, Any])
| 18 | return doc |
| 19 | |
| 20 | def text_replace(text: str, params: Dict[str, Any]): |
| 21 | keys = params.keys() |
| 22 | |
| 23 | # find all keys in text |
| 24 | exiting_keys = [] |
| 25 | for key in keys: |
| 26 | if f"$${key}$$" in text: |
| 27 | exiting_keys.append(key) |
| 28 | |
| 29 | # get all values of exiting keys |
| 30 | exiting_values = [params[key] for key in exiting_keys] |
| 31 | |
| 32 | # if there is None in exiting_values, return None |
| 33 | if None in exiting_values: |
| 34 | return None |
| 35 | else: |
| 36 | for key in exiting_keys: |
| 37 | if isinstance(params[key], list) or isinstance(params[key], dict): |
| 38 | text = text.replace(f"$${key}$$", json.dumps(params[key], indent=4)) |
| 39 | else: |
| 40 | text = text.replace(f"$${key}$$", str(params[key])) |
| 41 | return text |
| 42 | |
| 43 | |
| 44 | def content_replace(content: str): |
no outgoing calls
no test coverage detected