Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tiangolo
Copy link
Member

@tiangolo tiangolo commented Nov 28, 2023

πŸ”§ Update config with new pymdown extensions

I updated the admonition syntax automatically with this script:

import os
import re
import subprocess
from pathlib import Path

base_dir = Path(__file__).parent.parent

def update_admonition():
    os.chdir(base_dir)
    md_files = list(Path("docs").glob("**/*.md"))
    # md_files = [Path("docs/db-to-code.md")]
    re_str = r"!!! (?P<type>[^\n\"]*)\s?(\"(?P<title>[^\n\"]*)\")?\n(?P<content>(\n|    .*)*)\n*"
    # md_file = md_files[25]
    for md_file in md_files:
        content = md_file.read_text()

        def replace(match: re.Match):
            type_ = match.group("type")
            title = match.group("title")
            block = match.group("content")
            deindented_block = block.replace("    ", "")
            result = f"/// {type_}"
            if title:
                result += f" | {title}"
            result += f"\n\n{deindented_block.strip()}\n\n"
            result += "///\n\n"
            return result

        new_content = re.sub(re_str, replace, content)
        md_file.write_text(new_content)


if __name__ == "__main__":
    update_admonition()

@github-actions
Copy link
Contributor

πŸ“ Docs preview for commit 6a10132 at: https://0be9f547.sqlmodel.pages.dev

@tiangolo tiangolo merged commit a95bd38 into main Nov 28, 2023
@tiangolo tiangolo deleted the upgrade-pymdownx-syntax branch November 28, 2023 20:50
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.

2 participants