def _extract_metadata(self, raw_meta: dict[str, Any]) -> Metadata:
        """Extract structured metadata from Pandoc JSON metadata.

        Args:
            raw_meta: The raw metadata from Pandoc

        Returns:
            Structured metadata
        """
        meta: Metadata = {}

        if (
            "citations" in raw_meta
            and isinstance(raw_meta["citations"], list)
            and (
                citations := [
                    c["citationId"] for c in raw_meta["citations"] if isinstance(c, dict) and "citationId" in c
                ]
            )
        ):
            meta["citations"] = citations

        for key, value in raw_meta.items():
            if key == "citations":
                continue

            pandoc_key = self._get_pandoc_key(key)
            if pandoc_key is None:
                continue

            if key == "valid" and isinstance(value, dict) and value.get("t") == "MetaString" and "c" in value:
                meta[key] = value["c"]  # type: ignore[literal-required]
                continue

            extracted = self._extract_meta_value(value)
            if extracted:
                if pandoc_key in ("languages", "authors"):
                    extracted = [extracted]  # type: ignore[list-item]
                meta[pandoc_key] = extracted  # type: ignore[literal-required]

        citations_from_blocks = [
            cite["citationId"]
            for block in raw_meta.get("blocks", [])
            if block.get(TYPE_FIELD) == "Cite"
            for cite in block.get(CONTENT_FIELD, [[{}]])[0]
            if isinstance(cite, dict)
        ]
        if citations_from_blocks and "citations" not in meta:
            meta["citations"] = citations_from_blocks
        elif citations_from_blocks and "citations" in meta:
            meta["citations"].extend(citations_from_blocks)

        return meta
Extract structured metadata from Pandoc JSON metadata.

        Args:
            raw_meta: The raw metadata from Pandoc

        Returns:
            Structured metadata
        
kreuzberg/_extractors/_pandoc.py