Extract the ``description`` value from YAML frontmatter. Parses the YAML frontmatter so block scalar descriptions (``|`` and ``>``) keep their YAML semantics instead of being treated as raw text.
(content: str)
| 889 | |
| 890 | @staticmethod |
| 891 | def _extract_description(content: str) -> str: |
| 892 | """Extract the ``description`` value from YAML frontmatter. |
| 893 | |
| 894 | Parses the YAML frontmatter so block scalar descriptions (``|`` |
| 895 | and ``>``) keep their YAML semantics instead of being treated as |
| 896 | raw text. |
| 897 | """ |
| 898 | |
| 899 | frontmatter_text, _ = TomlIntegration._split_frontmatter(content) |
| 900 | if not frontmatter_text: |
| 901 | return "" |
| 902 | try: |
| 903 | frontmatter = yaml.safe_load(frontmatter_text) or {} |
| 904 | except yaml.YAMLError: |
| 905 | return "" |
| 906 | |
| 907 | if not isinstance(frontmatter, dict): |
| 908 | return "" |
| 909 | |
| 910 | description = frontmatter.get("description", "") |
| 911 | if isinstance(description, str): |
| 912 | return description |
| 913 | return "" |
| 914 | |
| 915 | @staticmethod |
| 916 | def _split_frontmatter(content: str) -> tuple[str, str]: |