Saves the snippet. If the path is absolute, it saves it in that location. Otherwise, the preffix and suffix are added according to format: - latex - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> tex_snippets - su
(self, filenameOrPath: str | Path)
| 681 | return f'Snippet("{self.snippet}", format="{self.format}")' |
| 682 | |
| 683 | def save(self, filenameOrPath: str | Path): |
| 684 | """ |
| 685 | Saves the snippet. |
| 686 | |
| 687 | If the path is absolute, it saves it in that location. |
| 688 | Otherwise, the preffix and suffix are added according to format: |
| 689 | |
| 690 | - latex |
| 691 | |
| 692 | - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> tex_snippets |
| 693 | - suffix: '.tex' |
| 694 | |
| 695 | - rst |
| 696 | |
| 697 | - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> rst_snippets |
| 698 | - suffix: '.rst' |
| 699 | - expressions and inline equations are appended to the file as: |
| 700 | |
| 701 | \\|<variable name>\\| = <expr>\\|<inline equation> |
| 702 | |
| 703 | - myst |
| 704 | |
| 705 | - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> myst_snippets |
| 706 | - suffix: '.md' |
| 707 | |
| 708 | - html |
| 709 | |
| 710 | - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> html_snippets |
| 711 | - suffix: '.html |
| 712 | |
| 713 | - md |
| 714 | |
| 715 | - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> md_snippets |
| 716 | - suffix: '.md' |
| 717 | |
| 718 | """ |
| 719 | if self.snippet != None: |
| 720 | if not filenameOrPath: |
| 721 | raise ValueError("No filename given to save snippet.") |
| 722 | if self.mode.lower() not in ["a", "w"]: |
| 723 | raise ValueError("Mode must be 'a' or 'w'.") |
| 724 | if isinstance(filenameOrPath, Path): |
| 725 | filenameOrPath = str(filenameOrPath) |
| 726 | if os.path.isabs(filenameOrPath): |
| 727 | filePath = filenameOrPath |
| 728 | else: |
| 729 | filePath = self._prefix + filenameOrPath + self._suffix |
| 730 | with open(filePath, self.mode) as f: |
| 731 | f.write(self.snippet) |
| 732 | |
| 733 | class _BaseFormatter: |
| 734 | """ |
no test coverage detected