Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摑 Update details syntax with new pymdown extensions format #713

Merged
merged 1 commit into from Nov 28, 2023

Conversation

tiangolo
Copy link
Owner

@tiangolo tiangolo commented Nov 28, 2023

馃摑 Update details syntax with new pymdown extensions format

I wrote a script to automatically update the details blocks:

import os
import re
from pathlib import Path

base_dir = Path(__file__).parent.parent

def update_details():
    os.chdir(base_dir)
    md_files = list(Path("docs").glob("**/*.md"))
    # md_files = [Path("docs/advanced/decimal.md")]
    re_str = r"<summary>((\n|.)*)</summary>"
    # md_file = md_files[25]
    for md_file in md_files:
        content = md_file.read_text()
        new_content = content
        all_starts = re.finditer("<details>", content)
        all_ends = re.finditer("</details>", content)
        for start, end in zip(all_starts, all_ends):
            sub_content = content[start.start() : end.end()]
            m = re.search(re_str, sub_content)
            assert m
            summary = m.group(1).strip()
            sub_content_internal = content[start.end() : end.start()].strip()
            sub_content_no_summary = re.sub(re_str, "", sub_content_internal).strip()
            new_sub_content = f"/// details | {summary}\n\n{sub_content_no_summary}\n\n///"
            new_content = new_content.replace(sub_content, new_sub_content)

        md_file.write_text(new_content)

if __name__ == "__main__":
    update_details()

Copy link

馃摑 Docs preview for commit 34a85e9 at: https://ee7298be.sqlmodel.pages.dev

@tiangolo tiangolo merged commit 799d0aa into main Nov 28, 2023
14 checks passed
@tiangolo tiangolo deleted the details branch November 28, 2023 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant