diff --git a/assets/js/hvac-ai-assist.js b/assets/js/hvac-ai-assist.js index b4ef64a0..52ed01a4 100644 --- a/assets/js/hvac-ai-assist.js +++ b/assets/js/hvac-ai-assist.js @@ -568,17 +568,20 @@ jQuery(document).ready(function($) { // Apply description (handle TinyMCE, regular textarea, and rich text editor) if (data.description) { + // Convert markdown to HTML for proper rich text editor formatting + const htmlContent = this.markdownToHtml(data.description); + // Try TinyMCE first if available if (typeof tinyMCE !== 'undefined' && tinyMCE.get('event_description')) { - tinyMCE.get('event_description').setContent(data.description); + tinyMCE.get('event_description').setContent(htmlContent); } else { - // Update the hidden textarea - $('#event_description, [name="event_description"]').val(data.description); + // Update the hidden textarea with HTML content + $('#event_description, [name="event_description"]').val(htmlContent); // Also update the visible rich text editor div if it exists const $richEditor = $('#event-description-editor'); if ($richEditor.length && $richEditor.is('[contenteditable]')) { - $richEditor.html(data.description); + $richEditor.html(htmlContent); } } } @@ -707,6 +710,85 @@ jQuery(document).ready(function($) { alert(message); }, + /** + * Convert markdown to HTML for rich text editor + */ + markdownToHtml: function(markdown) { + let html = markdown; + + // Convert headers (## -> h2, ### -> h3, etc.) + html = html.replace(/^### (.+)$/gm, '

$1

'); + html = html.replace(/^## (.+)$/gm, '

$1

'); + html = html.replace(/^# (.+)$/gm, '

$1

'); + + // Convert bold text (**text** -> text) + html = html.replace(/\*\*([^*]+)\*\*/g, '$1'); + + // Convert italic text (*text* -> text) + html = html.replace(/\*([^*]+)\*/g, '$1'); + + // Convert bullet lists (* item -> ) + html = html.replace(/^\* (.+)$/gm, '
  • $1
  • '); + + // Wrap consecutive
  • items in