יחידה:מקרא

גרסה מ־02:23, 2 בדצמבר 2026 מאת שיע בוט (שיחה | תרומות) (ניווט, מפתח פסוקים וייחוס לתבנית פרק תנך)
(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:מקרא/תיעוד

local p = {}

local function chapterData(frame)
    return mw.loadData('Module:מקרא/' .. frame.args[1])
end

local function displayText(text, edition, fullName, largeInitial, nameAliases, keepElohim)
    if not fullName then
        for name, alias in pairs(nameAliases or {}) do
            text = text:gsub(name, alias)
        end
        if not keepElohim then
            if edition == 'כתיב' then
                text = text:gsub('אלהים', 'אלוקים')
            else
                text = text:gsub('אֱלֹה', 'אֱלֹק')
            end
        end
    end

    if largeInitial then
        local first = edition == 'כתיב' and 'ב' or 'בְּ'
        if text:sub(1, #first) == first then
            text = '<big>' .. first .. '</big>' .. text:sub(#first + 1)
        end
    end
    return text
end

function p.verse(frame)
    local data = chapterData(frame)
    local verseNumber, edition = frame.args[2], frame.args[3]
    for _, record in ipairs(data.verses) do
        if record.number == verseNumber then
            local text = assert(record[edition], 'מהדורת מקרא לא מוכרת')
            return displayText(text, edition, frame.args[4] == 'מקור', record.largeInitial, data.nameAliases, record.keepElohim)
        end
    end
    error('פסוק לא נמצא בפרק')
end

local headings = {
    {'כתיב', 'כתיב (אותיות בלבד)'},
    {'ניקוד', 'מנוקד'},
    {'שורות', 'מנוקד בשורות'},
    {'טעמים', 'עם טעמי המקרא'},
}

function p.chapter(frame)
    local data = chapterData(frame)
    local view = frame.args[2]
    local edition = view == 'שורות' and 'ניקוד' or view
    local style = [[font-family: SBL Hebrew, Ezra SIL, Noto Serif Hebrew, serif; font-size:1.35em; line-height:1.8]]
    local lines = {}
    if frame.args['ניווט'] ~= 'לא' then
        local previous = data.previousChapter and '[[' .. data.previousChapter .. '|הפרק הקודם]] • ' or ''
        lines[#lines + 1] = previous .. '[[' .. data.book .. '|ספר ' .. data.book .. ']] • פרק ' .. data.number .. ' • [[' .. data.nextChapter .. '|הפרק הבא]]'
        lines[#lines + 1] = ''

        local navigation = {}
        for _, item in ipairs(headings) do
            local destination, label = unpack(item)
            navigation[#navigation + 1] = destination == view and label or
                '[[' .. data.chapter .. '/' .. destination .. '|' .. label .. ']]'
        end
        lines[#lines + 1] = table.concat(navigation, ' • ')
        lines[#lines + 1] = ''
    end
    lines[#lines + 1] = '<div class="ct-mikra-editions" lang="hbo" style="' .. style .. '">'

    for index, record in ipairs(data.verses) do
        local number = record.number
        local text = assert(record[edition], 'מהדורת מקרא לא מוכרת')
        local alias = displayText(text, edition, false, record.largeInitial, data.nameAliases, record.keepElohim)
        local source = displayText(text, edition, true, record.largeInitial, data.nameAliases, record.keepElohim)
        local label = data.number .. '_' .. number
        local target = '[[:קטגוריה:' .. data.chapter .. ' ' .. number .. '|' .. number .. ']]'
        local verse = '<span id="' .. label .. '"></span><span id="' .. number .. '"></span>'
        if edition == 'טעמים' and record.aliyah then
            verse = verse .. '<small>[' .. record.aliyah .. ']</small> '
        end
        verse = verse .. '<small>' .. target .. '</small> '
        if alias ~= source then
            verse = verse .. '<span class="ct-mikra-alias">' .. alias ..
                '</span><span class="ct-mikra-source" style="display:none">' .. source .. '</span>'
        else
            verse = verse .. source
        end
        if view ~= 'שורות' and record.cantillationSection then
            verse = verse .. ' <small>[[' .. data.chapter .. '/טעמים#' ..
                record.cantillationSection .. '|שתי מערכות הטעמים]]</small>'
        end
        lines[#lines + 1] = verse
        if data.verses[index + 1] ~= nil and (view == 'שורות' or record.paragraphEnd) then
            lines[#lines + 1] = ''
        end
    end
    lines[#lines + 1] = '</div>'
    return table.concat(lines, '\n')
end


local genesisChapters = { 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י', 'יא', 'יב', 'יג', 'יד', 'טו', 'טז', 'יז', 'יח', 'יט', 'כ', 'כא', 'כב', 'כג', 'כד', 'כה', 'כו', 'כז', 'כח', 'כט', 'ל', 'לא', 'לב', 'לג', 'לד', 'לה', 'לו', 'לז', 'לח', 'לט', 'מ', 'מא', 'מב', 'מג', 'מד', 'מה', 'מו', 'מז', 'מח', 'מט', 'נ' }

function p.chapterList(frame)
    local data = chapterData(frame)
    local result = { '[[:קטגוריה:תנ"ך|תנ״ך]] &gt; [[' .. data.book .. ']]' }
    if data.book == 'בראשית' then
        local links = {}
        for _, number in ipairs(genesisChapters) do
            if number == data.number then
                links[#links + 1] = '<strong>' .. number .. '</strong>'
            else
                links[#links + 1] = '[[' .. data.book .. ' ' .. number .. '|' .. number .. ']]'
            end
        end
        result[#result + 1] = table.concat(links, ' • ')
    end
    return table.concat(result, ' &gt; ')
end

function p.chapterHeading(frame)
    local data = chapterData(frame)
    local previous = data.previousChapter or data.book
    local number = data.number
    local length = mw.ustring.len(number)
    if length == 1 then
        number = number .. '׳'
    else
        number = mw.ustring.sub(number, 1, length - 1) .. '״' .. mw.ustring.sub(number, length)
    end
    local links = {
        '[[' .. previous .. '|&lt;&lt;]]',
        '<strong>[[' .. data.book .. '|ספר ' .. data.book .. ']] • פרק ' .. number .. '</strong>',
    }
    if data.nextChapter then
        links[#links + 1] = '[[' .. data.nextChapter .. '|&gt;&gt;]]'
    end
    return table.concat(links, ' &#124; ')
end

function p.verseList(frame)
    local data = chapterData(frame)
    local links = {}
    for _, verse in ipairs(data.verses) do
        links[#links + 1] = '[[:קטגוריה:' .. data.chapter .. ' ' .. verse.number .. '|' .. verse.number .. ']]'
    end
    return table.concat(links, ' · ')
end

function p.attribution(frame)
    local data = chapterData(frame)
    local source = data.revisions and data.revisions['טעמים']
    local revision = source and source:match('[?&]oldid=(%d+)')
    local target = revision and 'Special:PermanentLink/' .. revision or data.chapter .. '/טעמים'
    return '<small>נוסח המקרא מתוך [[wikisource:he:' .. target ..
        '|מקרא על פי המסורה בוויקיטקסט]], ברישיון [https://creativecommons.org/licenses/by-sa/4.0/ CC BY-SA 4.0]. הותאמה תצוגת שמות הקודש.</small>'
end

return p