mintlify-convert 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ """
2
+ Mintlify Convert - Convert MDX documentation to Mintlify format
3
+ """
4
+
5
+ __version__ = "2.0.0"
6
+ __author__ = "Olamideod"
7
+
8
+ from .converter import MintlifyConverter
9
+ from .cli import main
10
+ from .navigation import generate_docs_json, generate_enhanced_mint_json
11
+ from .utils import process_file, process_directory
12
+
13
+ __all__ = [
14
+ "MintlifyConverter",
15
+ "main",
16
+ "generate_docs_json",
17
+ "generate_enhanced_mint_json",
18
+ "process_file",
19
+ "process_directory",
20
+ ]
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command-line interface for Mintlify Convert.
4
+ """
5
+
6
+ import argparse
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from .utils import check_paths, find_mdx_files, process_file, process_directory
11
+ from .navigation import generate_docs_json, generate_enhanced_mint_json
12
+
13
+
14
+ def main(argv=None):
15
+ """Main CLI entry point."""
16
+ parser = argparse.ArgumentParser(
17
+ description="Convert MDX files to Mintlify format (v2 - Enhanced)",
18
+ formatter_class=argparse.RawDescriptionHelpFormatter,
19
+ epilog="""
20
+ Examples:
21
+ # Convert a single file
22
+ mintlify-convert input.mdx -o output.mdx
23
+
24
+ # Convert a directory with assets
25
+ mintlify-convert docs/ -o mintlify-docs/ --download-assets
26
+
27
+ # Generate docs.json (use --legacy-mint-json for the older mint.json)
28
+ mintlify-convert docs/ -o mintlify-docs/ --generate-config --sort-pages
29
+
30
+ # Validate output
31
+ mintlify-convert docs/ -o mintlify-docs/ --validate
32
+
33
+ # Full conversion with all features
34
+ mintlify-convert docs/ -o mintlify-docs/ \\
35
+ --generate-config \\
36
+ --download-assets \\
37
+ --validate \\
38
+ --sort-pages \\
39
+ --project-name "My API Docs"
40
+ """,
41
+ )
42
+
43
+ parser.add_argument("input", type=str, help="Input MDX file or directory")
44
+ parser.add_argument("-o", "--output", type=str, help="Output file or directory")
45
+
46
+ # Frontmatter options
47
+ parser.add_argument("--icon", type=str, help="Icon for frontmatter")
48
+ parser.add_argument("--mode", type=str, help='Mode for frontmatter (e.g., "wide")')
49
+
50
+ # Processing options
51
+ parser.add_argument(
52
+ "--download-assets", action="store_true", help="Download and copy image assets to /images"
53
+ )
54
+ parser.add_argument(
55
+ "--validate", action="store_true", help="Validate MDX output and report errors"
56
+ )
57
+ parser.add_argument("--verbose", action="store_true", help="Show detailed error messages")
58
+
59
+ # Navigation options
60
+ parser.add_argument(
61
+ "--generate-config",
62
+ action="store_true",
63
+ help="Generate docs.json (navigation and branding) in the output directory",
64
+ )
65
+ parser.add_argument(
66
+ "--legacy-mint-json",
67
+ action="store_true",
68
+ help="With --generate-config, write the legacy mint.json instead of docs.json",
69
+ )
70
+ parser.add_argument(
71
+ "--generate-mint-json",
72
+ action="store_true",
73
+ help="Deprecated alias for --generate-config --legacy-mint-json",
74
+ )
75
+ parser.add_argument(
76
+ "--sort-pages", action="store_true", help="Sort pages alphabetically within groups"
77
+ )
78
+ parser.add_argument(
79
+ "--project-name",
80
+ type=str,
81
+ default="Documentation",
82
+ help="Project name for the generated config",
83
+ )
84
+
85
+ # Branding options
86
+ parser.add_argument("--primary-color", type=str, help="Primary brand color")
87
+ parser.add_argument("--light-color", type=str, help="Light brand color")
88
+ parser.add_argument("--dark-color", type=str, help="Dark brand color")
89
+ parser.add_argument("--support-url", type=str, help="Support URL for topbar")
90
+ parser.add_argument("--dashboard-url", type=str, help="Dashboard URL for CTA button")
91
+ parser.add_argument("--twitter", type=str, help="Twitter URL")
92
+ parser.add_argument("--github", type=str, help="GitHub URL")
93
+ parser.add_argument("--linkedin", type=str, help="LinkedIn URL")
94
+
95
+ args = parser.parse_args(argv)
96
+
97
+ if args.generate_mint_json:
98
+ print(
99
+ "Warning: --generate-mint-json is deprecated; use --generate-config --legacy-mint-json",
100
+ file=sys.stderr,
101
+ )
102
+ args.generate_config = True
103
+ args.legacy_mint_json = True
104
+ if args.legacy_mint_json and not args.generate_config:
105
+ parser.error("--legacy-mint-json requires --generate-config")
106
+
107
+ input_path = Path(args.input)
108
+
109
+ if not input_path.exists():
110
+ print(f"Error: {input_path} does not exist", file=sys.stderr)
111
+ sys.exit(1)
112
+
113
+ kwargs = vars(args)
114
+
115
+ if input_path.is_file():
116
+ output_path = Path(args.output) if args.output else None
117
+ if output_path is not None and output_path.is_dir():
118
+ output_path = output_path / input_path.name
119
+ if args.generate_config:
120
+ print(
121
+ "Warning: --generate-config only applies to directory conversion; ignoring",
122
+ file=sys.stderr,
123
+ )
124
+ success, _ = process_file(input_path, output_path, **kwargs)
125
+ if not success:
126
+ sys.exit(1)
127
+ else:
128
+ if not args.output:
129
+ print("Error: Output directory required for directory conversion", file=sys.stderr)
130
+ sys.exit(1)
131
+
132
+ output_dir = Path(args.output)
133
+ problem = check_paths(input_path, output_dir)
134
+ if problem:
135
+ print(f"Error: {problem}", file=sys.stderr)
136
+ sys.exit(1)
137
+
138
+ file_metadata = process_directory(input_path, output_dir, **kwargs)
139
+
140
+ if args.generate_config and file_metadata:
141
+ nav_names = (
142
+ "project_name",
143
+ "primary_color",
144
+ "light_color",
145
+ "dark_color",
146
+ "support_url",
147
+ "dashboard_url",
148
+ "twitter",
149
+ "github",
150
+ "linkedin",
151
+ "sort_pages",
152
+ )
153
+ nav_kwargs = {k: kwargs[k] for k in nav_names if kwargs.get(k) is not None}
154
+ try:
155
+ if args.legacy_mint_json:
156
+ generate_enhanced_mint_json(
157
+ file_metadata, output_dir / "mint.json", **nav_kwargs
158
+ )
159
+ else:
160
+ generate_docs_json(file_metadata, output_dir / "docs.json", **nav_kwargs)
161
+ except (ValueError, OSError) as e:
162
+ print(f"Error: {e}", file=sys.stderr)
163
+ sys.exit(1)
164
+
165
+ if len(file_metadata) < len(find_mdx_files(input_path)):
166
+ sys.exit(1)
167
+
168
+
169
+ if __name__ == "__main__":
170
+ main()