מהדר שפת א

קוד בשפת א

`; } /* ============================== יצירת תוכן ============================== */ function createHTML(value) { /* * הטקסט עובר escape כדי שהמשתמש * לא יוכל לשבור את ה-HTML. */ var text = escapeHTML(value.trim()); return ( '
' + text + '
\n' ); } /* ============================== הגנה על HTML ============================== */ function escapeHTML(text) { return String(text) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } /* ============================== פתיחת העמוד המתורגם ============================== */ function openTranslatedPage() { if (!generatedHTML) { return; } /* * יצירת קובץ HTML זמני */ var blob = new Blob( [generatedHTML], { type: "text/html;charset=utf-8" } ); var url = URL.createObjectURL(blob); /* * פתיחה בעמוד חדש */ htmlWindow = window.open( url, "_blank" ); /* * לא מוחקים את ה-URL מיד, * כדי שהעמוד החדש יספיק להיטען. */ setTimeout( function() { URL.revokeObjectURL(url); }, 60000 ); } /* ============================== העתקת HTML ============================== */ function copyHTML() { if (!generatedHTML) { return; } if ( navigator.clipboard && window.isSecureContext ) { navigator.clipboard .writeText(generatedHTML) .then(function() { showMessage( "✓ ה־HTML הועתק בהצלחה", true ); }) .catch(function() { fallbackCopy(); }); } else { fallbackCopy(); } } function fallbackCopy() { var textarea = document.createElement( "textarea" ); textarea.value = generatedHTML; textarea.style.position = "fixed"; textarea.style.left = "-9999px"; document.body.appendChild( textarea ); textarea.select(); try { document.execCommand( "copy" ); showMessage( "✓ ה־HTML הועתק בהצלחה", true ); } catch (error) { showMessage( "לא ניתן להעתיק", false ); } document.body.removeChild( textarea ); } /* ============================== הורדת HTML ============================== */ function downloadHTML() { if (!generatedHTML) { return; } var blob = new Blob( [generatedHTML], { type: "text/html;charset=utf-8" } ); var url = URL.createObjectURL(blob); var link = document.createElement("a"); link.href = url; link.download = "site.html"; document.body.appendChild( link ); link.click(); document.body.removeChild( link ); setTimeout( function() { URL.revokeObjectURL(url); }, 1000 ); } /* ============================== הודעה ============================== */ function showMessage( text, success ) { var message = document.getElementById( "message" ); message.textContent = text; message.className = success ? "success" : "error"; }