{"id":30985242,"url":"https://github.com/samdc73/mdxjs-py","last_synced_at":"2025-09-12T13:10:04.762Z","repository":{"id":312645277,"uuid":"1048180377","full_name":"SamDc73/mdxjs-py","owner":"SamDc73","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-01T06:27:31.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-01T06:44:30.322Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SamDc73.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-01T04:01:15.000Z","updated_at":"2025-09-01T06:39:56.000Z","dependencies_parsed_at":"2025-09-01T06:44:34.101Z","dependency_job_id":"34d6eb24-7a51-40c7-a46a-aee8719a62dd","html_url":"https://github.com/SamDc73/mdxjs-py","commit_stats":null,"previous_names":["samdc73/mdxjs-py"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/SamDc73/mdxjs-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamDc73%2Fmdxjs-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamDc73%2Fmdxjs-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamDc73%2Fmdxjs-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamDc73%2Fmdxjs-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamDc73","download_url":"https://codeload.github.com/SamDc73/mdxjs-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamDc73%2Fmdxjs-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274816963,"owners_count":25355225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-12T13:10:00.614Z","updated_at":"2025-09-12T13:10:04.731Z","avatar_url":"https://github.com/SamDc73.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mdxjs-py\n\nPython bindings for [mdxjs-rs](https://github.com/wooorm/mdxjs-rs), a Rust implementation of MDX.\n\n**⚠️ Alpha Software**: This package is in early development. The API may change between versions.\n\n## Features\n\n- Fast MDX compilation via Rust (10-100x faster than Node.js subprocess)\n- Simple Python API mirroring @mdx-js/mdx\n- Zero dependencies (beyond the compiled extension)\n- Helpful error messages with line/column information\n- Full MDX 2 support via mdxjs-rs\n\n## Installation\n\n```bash\npip install mdxjs-py\n```\n\n**Note**: Currently only Linux x86_64 wheels are provided. For other platforms, you'll need Rust installed to build from source:\n\n```bash\n# Install Rust first\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n\n# Then install from PyPI (will compile automatically)\npip install mdxjs-py\n```\n\n## Usage\n\n### Basic Compilation\n\n```python\nfrom mdxjs_py import compile\n\n# Compile MDX to JavaScript\nmdx_content = \"\"\"\n# Hello World\n\nThis is **MDX** content with \u003cButton onClick={() =\u003e alert('hi!')}\u003eJSX\u003c/Button\u003e!\n\"\"\"\n\ntry:\n    js_output = compile(mdx_content)\n    print(js_output)\nexcept ValueError as e:\n    print(f\"MDX compilation failed: {e}\")\n```\n\n### Validation\n\nUse `compile()` to validate MDX syntax:\n\n```python\nfrom mdxjs_py import compile\n\ndef validate_mdx(content: str) -\u003e tuple[bool, str | None]:\n    \"\"\"Validate MDX content.\n\n    Returns:\n        (is_valid, error_message)\n    \"\"\"\n    try:\n        compile(content)\n        return True, None\n    except ValueError as e:\n        return False, str(e)\n\n# Example usage\ncontent = \"\u003cButton\u003eUnclosed tag\"\nis_valid, error = validate_mdx(content)\nif not is_valid:\n    print(f\"Invalid MDX: {error}\")\n    # Output: Invalid MDX: Expected a closing tag for `\u003cButton\u003e`\n```\n\n### Configuration Options\n\n```python\nfrom mdxjs_py import compile\n\n# With options (matches @mdx-js/mdx API)\njs_output = compile(\n    mdx_content,\n    development=True,  # Enable development mode\n    jsx_runtime=\"automatic\",  # or \"classic\"\n    jsx_import_source=\"react\",  # for automatic runtime\n)\n```\n\n## API Reference\n\n### `compile(source: str, **options) -\u003e str`\n\nCompile MDX source to JavaScript. API-compatible with @mdx-js/mdx.\n\n**Parameters:**\n\n- `source` (str): The MDX source code to compile\n- `development` (bool, optional): Enable development mode\n- `jsx` (bool, optional): Keep JSX (default: False, compiles to JS)\n- `jsx_runtime` (str, optional): \"automatic\" or \"classic\"\n- `jsx_import_source` (str, optional): Package for automatic JSX runtime\n- `pragma` (str, optional): JSX pragma for classic runtime\n- `pragma_frag` (str, optional): JSX pragma fragment for classic runtime\n- `pragma_import_source` (str, optional): Pragma import source\n- `provider_import_source` (str, optional): Provider import source\n\n**Returns:**\n\n- `str`: Compiled JavaScript code\n\n**Raises:**\n\n- `ValueError`: If MDX compilation fails with detailed error message\n\n### `compile_sync(source: str, **options) -\u003e str`\n\nSynchronous version of `compile()` (alias for compatibility).\n\n### `is_available() -\u003e bool`\n\nCheck if the Rust module is built and available.\n\n## Common Use Cases\n\n### 1. Validate User-Generated MDX\n\n```python\ndef process_user_mdx(content: str) -\u003e dict:\n    \"\"\"Process and validate user MDX content.\"\"\"\n    try:\n        js_output = compile(content)\n        return {\n            \"success\": True,\n            \"output\": js_output\n        }\n    except ValueError as e:\n        # Extract line/column from error\n        error_str = str(e)\n        return {\n            \"success\": False,\n            \"error\": error_str,\n            \"hint\": \"Check for unclosed tags or invalid JSX\"\n        }\n```\n\n### 2. MDX Syntax Checking in CI/CD\n\n```python\nimport glob\nfrom pathlib import Path\nfrom mdxjs_py import compile\n\ndef check_all_mdx_files(directory: str) -\u003e bool:\n    \"\"\"Validate all MDX files in a directory.\"\"\"\n    all_valid = True\n\n    for mdx_path in Path(directory).glob(\"**/*.mdx\"):\n        try:\n            with open(mdx_path, 'r') as f:\n                compile(f.read())\n            print(f\"✅ {mdx_path}\")\n        except ValueError as e:\n            print(f\"❌ {mdx_path}: {e}\")\n            all_valid = False\n\n    return all_valid\n```\n\n### 3. Pre-process MDX for Frontend\n\n```python\ndef prepare_mdx_for_frontend(content: str, max_retries: int = 3) -\u003e str:\n    \"\"\"Validate and prepare MDX for frontend rendering.\"\"\"\n    for attempt in range(max_retries):\n        try:\n            # Validate compilation\n            compile(content)\n            return content\n        except ValueError as e:\n            if attempt == max_retries - 1:\n                # Return with warning comment\n                return f\"\u003c!-- MDX validation warning: {e} --\u003e\\n{content}\"\n            # Could attempt to fix common issues here\n            content = fix_common_mdx_issues(content)\n\n    return content\n```\n\n## Performance\n\nBenchmarked on an Intel i7-9750H:\n\n```python\nimport time\nfrom mdxjs_py import compile\n\ncontent = \"# Heading\\n\\nParagraph with **bold** text.\\n\\n\" * 100\n\n# Single compilation\nstart = time.time()\ncompile(content)\nprint(f\"Single: {(time.time() - start) * 1000:.2f}ms\")\n# Result: ~0.5ms\n\n# Bulk compilation\nstart = time.time()\nfor _ in range(1000):\n    compile(content)\nprint(f\"1000x: {time.time() - start:.2f}s\")\n# Result: ~0.5s (vs ~50s with Node.js subprocess)\n```\n\n## Development\n\n### Building from Source\n\n```bash\n# Clone the repository\ngit clone https://github.com/SamDc73/mdxjs-py\ncd mdxjs-py\n\n# Create virtual environment\npython -m venv venv\nsource venv/bin/activate\n\n# Install build dependencies\npip install maturin pytest\n\n# Build and install locally\nmaturin develop --release\n\n# Run tests\npytest tests/\n```\n\n### Architecture\n\nThis is a minimal Python binding to mdxjs-rs, designed for:\n\n- **Zero overhead** - Direct 1:1 binding to mdxjs-rs functions\n- **API compatibility** - Matches @mdx-js/mdx compile() API\n- **Simplicity** - No abstraction layers, just the binding\n\n## Credits\n\nThis package is a thin Python wrapper around:\n\n- **[mdxjs-rs](https://github.com/wooorm/mdxjs-rs)** by [Titus Wormer](https://github.com/wooorm) - The Rust MDX implementation that does all the heavy lifting\n- Built with **[PyO3](https://pyo3.rs)** - Rust bindings for Python\n- Packaged with **[maturin](https://maturin.rs)** - Build and publish Rust Python extensions\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\nThis package is MIT licensed, same as mdxjs-rs.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for release history.\n\n## Support\n\n- 🐛 [Report bugs](https://github.com/SamDc73/mdxjs-py/issues)\n- 💡 [Request features](https://github.com/SamDc73/mdxjs-py/issues)\n- 📖 [Documentation](https://github.com/SamDc73/mdxjs-py#readme)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdc73%2Fmdxjs-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamdc73%2Fmdxjs-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdc73%2Fmdxjs-py/lists"}