אונטערשייד צווישן ווערסיעס פון "באַניצער:תנא קמא/tanachLinks.js"

קיין רעדאגירונג באמערקונג
אין תקציר עריכה
אין תקציר עריכה
שורה 1: שורה 1:
$(document).ready(function() {
// Function to convert Tanakh citations to Sefaria links
     console.log("Tanach Citation Script Running"); // Debugging message
function convertTanakhCitations(wikitext) {
     $(".tanach-citation").each(function() {
  // Regular expression to match the {{תנ"ך|Sefer|Chapter|Verse}} pattern
        var $this = $(this);
  const regex = /{{תנ"ך\|([^|]+)\|([^|]+)\|([^|]+)}}/g;
        console.log("Found citation:", $this.text()); // Debugging each found citation
  return wikitext.replace(regex, function(match, sefer, chapter, verse) {
     // Construct the Sefaria URL
    const url = `https://www.sefaria.org/${sefer}.${chapter}.${verse}`;
    // Return the HTML link with Sefaria's logo
     return `<a href="${url}" target="_blank"><img src="https://www.sefaria.org/static/img/sefaria_logo.png" alt="Sefaria" style="vertical-align: middle; width: 20px; height: 20px;"/> ${sefer} ${chapter}:${verse}</a>`;
  });
}


        var sefer = $this.data("sefer");
// Example usage
        var perek = $this.data("perek");
const wikitext = 'Some text {{תנ"ך|Bamidbar|3|4}} more text.';
        var pasuk = $this.data("pasuk") || 1;
const convertedText = convertTanakhCitations(wikitext);
 
console.log(convertedText);
        console.log("Extracted:", sefer, perek, pasuk); // Debugging extracted values
 
        var sefariaUrl = `https://www.sefaria.org/${encodeURIComponent(sefer)}.${perek}.${pasuk}`;
        var iconHtml = `<a href="${sefariaUrl}" target="_blank" title="View on Sefaria">
            <img src="https://www.sefaria.org/static/img/favicon.ico" style="width: 16px; height: 16px; vertical-align: middle;" />
        </a>`;
 
        $this.append(' ' + iconHtml); // Append icon to the citation
    });
});