{# Live Markdown Editor (text-forge). Provides an "Edit" button on content pages that opens a split-pane editor with live preview using Pyodide + PyMdown Extensions. Config (mkdocs.yml -> plugins -> text-forge): text-forge: editor_enabled: true # Show editor button on content pages #} {% if text_forge_editor_enabled and page and page.content %} {% set edit_uri_parts = config.edit_uri.rstrip('/').split('/') %} {% set repo_base_path = '/'.join(edit_uri_parts[2:]) if edit_uri_parts|length > 2 else '' %} {% set full_file_path = (repo_base_path ~ '/' ~ page.file.src_path) if repo_base_path else page.file.src_path %} {% set editor_config = { 'sourceUrl': (config.repo_url ~ '/' ~ config.edit_uri ~ page.file.src_path)|e|replace('/blob/', '/raw/'), 'filePath': full_file_path|e, 'localFilePath': page.file.src_uri|e, 'fileName': page.file.name|e, 'sourceContent': (page._text_forge_original_source | default(page.markdown)), 'markdownExtensions': config.markdown_extensions, 'extensionConfigs': config.mdx_configs, 'github': { 'owner': config.repo_name.split('/')[0]|e, 'repo': config.repo_name.split('/')[1]|e, 'branch': (config.edit_uri.split('/')[1] if '/' in config.edit_uri else (config.remote_branch|default('main')))|e, 'apiUrl': 'https://api.github.com' } if config.repo_name else None } %} {% endif %}