diff --git a/markitect/plugins/builtin/markdown_commands.py b/markitect/plugins/builtin/markdown_commands.py index 6a3a1a1a..4af72626 100644 --- a/markitect/plugins/builtin/markdown_commands.py +++ b/markitect/plugins/builtin/markdown_commands.py @@ -249,8 +249,12 @@ def md_list_command(ctx, output_format, names_only): @click.option('--template', type=click.Choice(['basic', 'github', 'academic', 'dark']), default='basic', help='HTML template: basic (default), github, academic, or dark theme') @click.option('--css', type=click.Path(exists=True), help='Custom CSS file to inject into the template') +@click.option('--edit', is_flag=True, help='Enable instant markdown editing capabilities in the generated HTML') +@click.option('--editor-theme', type=click.Choice(['light', 'dark']), default='light', + help='Editor interface theme (light or dark)') +@click.option('--keyboard-shortcuts', is_flag=True, help='Enable keyboard shortcuts for editing actions') @click.pass_context -def md_render_command(ctx, input_file, output, template, css): +def md_render_command(ctx, input_file, output, template, css, edit, editor_theme, keyboard_shortcuts): """ Generate HTML with client-side JavaScript markdown rendering. @@ -264,6 +268,7 @@ def md_render_command(ctx, input_file, output, template, css): • YAML front matter support and metadata extraction • Multiple responsive template options • Custom CSS injection capability + • Optional instant editing capabilities with --edit flag • Graceful fallback if JavaScript fails INPUT_FILE: Path to the markdown file to render @@ -287,6 +292,12 @@ def md_render_command(ctx, input_file, output, template, css): # Academic paper with custom styling markitect md-render paper.md --template academic --css custom.css + # Enable instant editing capabilities + markitect md-render README.md --edit + + # Editing with dark editor theme and keyboard shortcuts + markitect md-render docs/guide.md --edit --editor-theme dark --keyboard-shortcuts + # Front matter will be parsed and available to JavaScript # Files with YAML front matter are fully supported """ @@ -328,7 +339,7 @@ def md_render_command(ctx, input_file, output, template, css): # Generate HTML with embedded markdown html_content = generate_html_with_embedded_markdown( - markdown_content, title, template, css_content, front_matter + markdown_content, title, template, css_content, front_matter, edit, editor_theme, keyboard_shortcuts ) # Determine output path @@ -411,12 +422,120 @@ TEMPLATE_STYLES = { } } -def generate_html_with_embedded_markdown(markdown_content, title, template, css_content, front_matter): - """Generate HTML with embedded markdown content for client-side rendering.""" +def generate_html_with_embedded_markdown(markdown_content, title, template, css_content, front_matter, edit=False, editor_theme='light', keyboard_shortcuts=False): + """Generate HTML with embedded markdown content for client-side rendering. + + Args: + markdown_content: The markdown content to embed + title: Page title + template: Template name (basic, github, academic, dark) + css_content: Custom CSS content to inject + front_matter: YAML front matter dictionary + edit: Enable editing capabilities + editor_theme: Editor theme (light or dark) + keyboard_shortcuts: Enable keyboard shortcuts + """ # Get template styles or default to basic styles = TEMPLATE_STYLES.get(template, TEMPLATE_STYLES['basic']) + # Build editor styles if editing is enabled + editor_styles = "" + if edit: + editor_styles = ''' + /* Markitect Editor Styles */ + .markitect-floating-header {{ + position: fixed; + top: 10px; + right: 10px; + background: rgba(0, 123, 255, 0.9); + color: white; + padding: 10px 20px; + border-radius: 20px; + font-size: 14px; + font-weight: bold; + box-shadow: 0 2px 10px rgba(0,0,0,0.2); + z-index: 1000; + display: none; + }} + .markitect-floating-header.show {{ + display: block; + }} + .markitect-section-editable {{ + position: relative; + cursor: pointer; + transition: background-color 0.2s; + }} + .markitect-section-editable:hover {{ + background-color: rgba(0, 123, 255, 0.1); + }} + .markitect-section-modified {{ + border-left: 4px solid #007bff; + padding-left: 16px; + }} + .markitect-edit-interface {{ + margin: 15px 0; + padding: 20px; + border: 2px dashed #007bff; + border-radius: 8px; + background: #f8f9fa; + }} + .markitect-edit-textarea {{ + width: 100%; + min-height: 150px; + font-family: 'Courier New', Consolas, monospace; + font-size: 14px; + padding: 10px; + border: 1px solid #ddd; + border-radius: 4px; + resize: vertical; + }} + .markitect-edit-actions {{ + margin-top: 10px; + text-align: right; + }} + .markitect-edit-btn {{ + margin-left: 10px; + padding: 8px 16px; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + }} + .markitect-btn-apply {{ + background-color: #28a745; + color: white; + }} + .markitect-btn-reset {{ + background-color: #ffc107; + color: #212529; + }} + .markitect-btn-cancel {{ + background-color: #6c757d; + color: white; + }} + .markitect-btn-save {{ + background-color: #007bff; + color: white; + padding: 10px 20px; + margin-left: 15px; + }} + ''' + + if editor_theme == 'dark': + editor_styles += ''' + /* Dark theme overrides */ + .markitect-edit-interface {{ + background: #2d2d2d; + border-color: #666; + }} + .markitect-edit-textarea {{ + background: #1a1a1a; + color: #f0f0f0; + border-color: #666; + }} + ''' + # HTML template with style variables html_template = ''' @@ -462,16 +581,19 @@ def generate_html_with_embedded_markdown(markdown_content, title, template, css_ color: {blockquote_color}; }} {css_content} + {editor_styles}
+ {editor_html} + {editor_scripts}