Given a `text` string return a YAML-safe version of the string suitable for use in a YAML output, i.e. that would not produce a invalid yaml if used in the output. This is done by trying to dump and load the text inside a data dictionary and if it fails, padding all the empty n
(text)
| 776 | |
| 777 | |
| 778 | def get_yaml_safe_text(text): |
| 779 | """ |
| 780 | Given a `text` string return a YAML-safe version of the |
| 781 | string suitable for use in a YAML output, i.e. that would not |
| 782 | produce a invalid yaml if used in the output. |
| 783 | |
| 784 | This is done by trying to dump and load the text inside a data |
| 785 | dictionary and if it fails, padding all the empty newlines with |
| 786 | a space. |
| 787 | """ |
| 788 | data = {"text": text} |
| 789 | yaml_string = saneyaml_dump(data) |
| 790 | try: |
| 791 | saneyaml_load(yaml_string) |
| 792 | except Exception: |
| 793 | text = text.replace('\n\n', '\n \n') |
| 794 | return text |
| 795 | |
| 796 | |
| 797 | def ignore_editor_tmp_files(location): |