מהדר שפת א

קוד שפת א

תוצאת HTML

עדיין לא נוצר קוד.

תצוגה מקדימה

התוצאה תוצג כאן.

פקודות מוגדרות

*א1* — הצג תוכן
*א2* — חפש תוכן
`; /* ========================================== קומפילציה ========================================== */ function compileCode() { const source = document.getElementById("code").value; try { if (!source.trim()) { throw new Error("לא הוזן קוד"); } const program = parseProgram(source); let html = ""; let preview = ""; for (let i = 0; i < program.length; i++) { const item = program[i]; let result = ""; if (item.command === "א1") { result = displayValue(item.value); } else if (item.command === "א2") { result = searchValue(item.value); } html += result + "\n"; preview += result + "\n"; } const fullHTML = HTML_HEAD + html + HTML_FOOT; document .getElementById("result") .textContent = fullHTML; document .getElementById("preview") .innerHTML = preview; } catch (error) { showError(error.message); } } /* ========================================== פירוק פקודות ========================================== */ function parseProgram(source) { const lines = source.split(/\r?\n/); const result = []; let i = 0; while (i < lines.length) { let line = lines[i]; let trimmed = line.trim(); /* שורה ריקה */ if (!trimmed) { i++; continue; } /* פקודה א1 */ let command = null; if (trimmed.indexOf("*א1*") === 0) { command = "א1"; } /* פקודה א2 */ else if ( trimmed.indexOf("*א2*") === 0 ) { command = "א2"; } else { throw new Error( "פקודה לא תקינה בשורה " + (i + 1) + ": " + trimmed ); } /* התוכן שאחרי הפקודה */ let value = trimmed.substring(4).trim(); i++; /* אם התוכן באותה שורה */ if (value) { result.push({ command: command, value: value }); continue; } /* תוכן בשורות הבאות */ let content = []; while (i < lines.length) { let next = lines[i]; let nextTrimmed = next.trim(); /* פקודה חדשה */ if ( nextTrimmed.indexOf("*א1*") === 0 || nextTrimmed.indexOf("*א2*") === 0 ) { break; } content.push(next); i++; } /* ניקוי שורות ריקות */ while ( content.length && content[0].trim() === "" ) { content.shift(); } while ( content.length && content[content.length - 1].trim() === "" ) { content.pop(); } value = content.join("\n").trim(); if (!value) { throw new Error( "חסר תוכן אחרי *" + command + "*" ); } result.push({ command: command, value: value }); } if (!result.length) { throw new Error( "לא נמצאו פקודות" ); } return result; } /* ========================================== א1 ========================================== */ function displayValue(value) { const text = value.trim(); /* URL */ if ( /^https?:\/\//i.test(text) ) { return displayURL(text); } /* טקסט */ return `
${escapeHTML(text)}
`; } /* ========================================== URL ========================================== */ function displayURL(url) { const lower = url.toLowerCase(); /* YouTube */ if ( lower.indexOf("youtube.com") !== -1 || lower.indexOf("youtu.be") !== -1 ) { const id = getYouTubeID(url); if (id) { return `
`; } } /* Vimeo */ if ( lower.indexOf("vimeo.com") !== -1 ) { const id = getVimeoID(url); if (id) { return `
`; } } /* תמונה */ if ( /\.(jpg|jpeg|png|gif|webp|svg)(\?.*)?$/i .test(url) ) { return `
`; } /* וידאו */ if ( /\.(mp4|webm|ogg|mov)(\?.*)?$/i .test(url) ) { return `
`; } /* אודיו */ if ( /\.(mp3|wav|m4a|aac|flac)(\?.*)?$/i .test(url) ) { return `
`; } /* קישור רגיל */ return `
${escapeHTML(url)}
`; } /* ========================================== א2 ========================================== */ function searchValue(query) { const encoded = encodeURIComponent(query); return `

תוצאות חיפוש עבור: ${escapeHTML(query)}

YouTube

פתח חיפוש YouTube
Google

פתח חיפוש Google
Bing

פתח חיפוש Bing
`; } /* ========================================== YouTube ========================================== */ function getYouTubeID(url) { try { const parsed = new URL(url); const host = parsed.hostname.toLowerCase(); /* youtu.be */ if ( host.indexOf("youtu.be") !== -1 ) { return parsed.pathname .replace("/", "") .split("/")[0]; } /* youtube.com */ if ( host.indexOf("youtube.com") !== -1 ) { /* v= */ const v = parsed.searchParams.get("v"); if (v) { return v; } /* shorts */ const shorts = parsed.pathname.match( /\/shorts\/([^/]+)/i ); if (shorts) { return shorts[1]; } /* embed */ const embed = parsed.pathname.match( /\/embed\/([^/]+)/i ); if (embed) { return embed[1]; } } } catch (error) { return null; } return null; } /* ========================================== Vimeo ========================================== */ function getVimeoID(url) { const match = url.match( /vimeo\.com\/(?:video\/)?(\d+)/i ); if (match) { return match[1]; } return null; } /* ========================================== Escape ========================================== */ function escapeHTML(text) { return String(text) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function escapeAttribute(text) { return escapeHTML(text); } /* ========================================== שגיאה ========================================== */ function showError(message) { document.getElementById("result").innerHTML = ""; const error = document.createElement("div"); error.className = "error"; error.textContent = "שגיאה במהדר\n\n" + message; document .getElementById("result") .appendChild(error); document .getElementById("preview") .innerHTML = '
' + escapeHTML(message) + '
'; } /* ========================================== העתקה ========================================== */ function copyResult() { const text = document .getElementById("result") .textContent; if (!text.trim()) { return; } if ( navigator.clipboard && navigator.clipboard.writeText ) { navigator.clipboard .writeText(text) .then(function() { copied(); }) .catch(function() { fallbackCopy(text); }); } else { fallbackCopy(text); } } /* ========================================== העתקה חלופית ========================================== */ function fallbackCopy(text) { const area = document.createElement("textarea"); area.value = text; area.style.position = "fixed"; area.style.left = "-9999px"; area.style.top = "0"; document.body.appendChild(area); area.focus(); area.select(); try { document.execCommand("copy"); copied(); } catch (error) { alert("ההעתקה נכשלה"); } area.remove(); } /* ========================================== הודעת העתקה ========================================== */ function copied() { const button = document.querySelector( ".secondary" ); const old = button.textContent; button.textContent = "הועתק!"; button.style.background = "#16803c"; setTimeout(function() { button.textContent = old; button.style.background = ""; }, 1500); } בדיקה מהירה: אחרי שאתה פותח את הקובץ, הדבק בעורך: *א1* שלום עולם ולחץ תרגם. אם גם הקובץ הזה לא נפתח בכלל בדפדפן, אז הבעיה כבר לא ב־RTL — במקרה כזה תגיד לי מה בדיוק מופיע בדפדפן (מסך לבן / שגיאה / האתר נפתח אבל הכפתור לא עובד / הקוד עדיין בורח), ואטפל בדיוק בתקלה.